I\'m new to iOS. I\'ve been trying to make an application that will store an image captured from the camera into CoreData
. I now know how to store data like
For Swift 5 and Swift 4.2
convert UIImage
to Data
:
let imageData = image.jpegData(compressionQuality: 1.0)
save to CoreData
:
let object = MyEntity(context: managedContext) //create object of type MyEntity
object.image = imageData //add image to object
do {
try managedContext.save() //save object to CoreData
} catch let error as NSError {
print("\(error), \(error.userInfo)")
}