dimanche 28 décembre 2014

Error saving UIImage to CoreData entity as Binary Data

When attempting to save a UIImage to a CoreData persistent store I am getting the following error:


NSConcreteMutableData CGImage]: unrecognized selector sent to instance 0x7fe85a4b5cd0 2014-12-28 20:27:16.307 MyAppName[1578:245578] Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSConcreteMutableData CGImage]: unrecognized selector sent to instance 0x7fe85a4b5cd0'


Here is where I create the UIImage instance:



let ipaIcon = CoreData.newIconWithImageAndName(UIImage(named: "IPA-Day.png")!, name: "IPA-Day")


This is the code where I am saving the converting the image to NSData and attempting to set it to the NSData property of the managed object:



func setImage(image: UIImage)
{
let data: NSData = UIImagePNGRepresentation(image)

self.image = data
}


This is a screen shot of my xcdatamodel: enter image description here


*** I am running the latest release of Xcode(6.1) using Swift(1.1) .




Aucun commentaire:

Enregistrer un commentaire