I am doing this online swift course and now I am trying to combine two different projects with each other to create my own project. Basically I had a task manager app but now I want to add an image to each task.
I can't get my head around the following:
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]) {
let image = info[UIImagePickerControllerOriginalImage] as UIImage
let imageData = UIImageJPEGRepresentation(image, 1.0);
let managedObjectContext = (UIApplication.sharedApplication().delegate as AppDelegate).managedObjectContext
let entityDescription = NSEntityDescription.entityForName("TaskModel", inManagedObjectContext: managedObjectContext!)
let taskItem = TaskModel(entity: entityDescription!, insertIntoManagedObjectContext: managedObjectContext!)
taskItem.image = imageData;
(UIApplication.sharedApplication().delegate as AppDelegate).saveContext()
self.dismissViewControllerAnimated(true, completion: nil)
}
When I run my app I get the following error:
2015-06-10 20:43:59.726 TaskIt[85735:13802555] -[TaskModel setImage:]: unrecognized selector sent to instance 0x792a4800
I figured out that when I comment out taskItem.image = imagaData; the code works. But I cant figure out what's wrong.
Anyone that can help me?
Looks like the
TaskModel
class does not have animage
property, and so you can't callsetImage:
on an object of this class (which is whattaskItem.image =
actually does.)