How to save layered uiimageview to core data (SWIFT5)

I am trying to save a drawing on top of a uiview with a image printed above it it. So UIVIEW > IMAGE > DRAWING. What is currently saving is nothing. It is just a blank white uiview. I want to save the layered image. func addArrow places the layered image over the imageview.

                                            var myLayer = CALayer()

var path = UIBezierPath()
var startPoint = CGPoint()
var touchPoint = CGPoint()

var drawPlace = UIImageView()

func save() {
guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else { return }

let managedContext = appDelegate.persistentContainer.viewContext

let entity = NSEntityDescription.entity(forEntityName: “Item”, in: managedContext)!

let item = NSManagedObject(entity: entity, insertInto: managedContext)

if let data = drawPlace.image?.pngData() {
item.setValue(data, forKey: “image”)

let fetch = NSFetchRequest(entityName: “Item”)

do {
let result = try? managedContext.fetch(fetch) as? [Item]
} catch {
print(“Could not save”)
func addArrowImageToButton(button: UIButton, arrowImage:UIImage = #imageLiteral(resourceName: “bb”) ) {
let btnSize:CGFloat = 32
let imageView = UIImageView(image: arrowImage)
let btnFrame = button.frame



@timswift Do you still have issues with this?

This topic was automatically closed after 166 days. New replies are no longer allowed.