我从照片库中获取所有图像,并且我想将其导入核心数据中。我试图将图像转换为NSData,以便将其保存在核心数据中。一些图像被转换,但其他图像不被转换。我收到以下错误:
**Data[602] <Error>: ImageIO: PNG zlib error**
我使用以下代码:
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!")
}
}
如何解决此问题?