Reputation: 41
I get all the images from a photo library and I want to import it in the core data. I am trying to convert the images to NSData, in order to save it in the core data. Some images are converted, but others are not. I get the following error:
**Data[602] <Error>: ImageIO: PNG zlib error**
I use the following code:
for(_ , value) in dictOfPhoto.enumerate() {
if let convertImage = UIImagePNGRepresentation(value.1) {
if let app = UIApplication.sharedApplication().delegate as? AppDelegate {
let connection = app.managedObjectContext
let imgN = NSEntityDescription.insertNewObjectForEntityForName("Images",
inManagedObjectContext: connection)
imgN.setValue(convertImage, forKey: "image")
imgN.setValue(folderName, forKey: "folderName")
do {
try connection.save()
// print("Image Is Save It")
} catch {
print(error)
}
}
} else {
//print("One Image Not Converted!")
}
}
How can I resolve this issue?
Upvotes: 1
Views: 309