Parham Hasaninia
Parham Hasaninia

Reputation: 23

How to save Image in Core Data

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

Answers (2)

vivekDas
vivekDas

Reputation: 1288

Convert UIImage to NSData and save.

To save: let data = UIImagePNGRepresentation(image)

To load: let image = UIImage(data: data)

Upvotes: 2

shivi_shub
shivi_shub

Reputation: 1058

Convert the image into Data form. Then save it as Binary data.

Upvotes: 0

Related Questions