Seb
Seb

Reputation: 53

How to save a UIImageView to a CoreData Database

What is the SIMPLEST way to save a UIImageView to a CoreData Database. I have tried this:

Save:

 UIImage *image = imageView.image;
    NSData *imageData = UIImagePNGRepresentation(image);
    [newContact setValue:imageData forKey:@"imageViewFinal"];

Retrive:

  imageView.image = [matches valueForKey:@"imageViewFinal"];

and I have added an Attribute called 'imageViewFinal' with a Binary Data type.

PROBLEM:

When I go to build it and click the save button, the app crashes, what's the problem?

Thanks, Seb.

Upvotes: 1

Views: 469

Answers (1)

Kjuly
Kjuly

Reputation: 35131

What @ShermanLo said is right, the crash log shows that you've modified your model but did not handle the conflict between the old & new store model versions in the right way.

So just delete your App in your device/simulator, and rebuild/run it.

Note: Whenever you've modified your models, you need to do it this way unless you offer an approach to handle. There're many related QAs on SO. :)

Upvotes: 1

Related Questions