Reputation: 23
I am trying to save an image to core data . I get an image from camera or photo library an store it to global UIImage variable . How can I insert this image to newPerson.image
let newPerson = NSEntityDescription.insertNewObject(forEntityName: "Person", into: manageObjectContext) as! Person
newPerson.age = age
newPerson.city = cityInput.text
newPerson.image = ????
I am using swift 4.
Upvotes: 0
Views: 187
Reputation: 1288
Convert UIImage
to NSData
and save.
To save: let data = UIImagePNGRepresentation(image)
To load: let image = UIImage(data: data)
Upvotes: 2