Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Google Sign In with OpenID
Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.

Images in CoreData

nd049nd049 Posts: 127Registered Users
Hi Everyone,

I am having a bit of an issue with saving an UIImage to my CoreData model. I am following the Recipes example for CoreData and I can't find where I went wrong. Once I select a photo (while view is editing) the image goes to the view ImageView, but then once I press the Done button my app crashes with the error:
[UIImage encodeWithCoder:]: unrecognized selector sent to instance 0x6083080
2011-07-03 19:40:28.988 BandManager[25028:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIImage encodeWithCoder:]: unrecognized selector sent to instance 0x6083080'
*** Call stack at first throw:
(
0 CoreFoundation 0x0171a5a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x0186e313 objc_exception_throw + 44
2 CoreFoundation 0x0171c0bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x0168b966 ___forwarding___ + 966
4 CoreFoundation 0x0168b522 _CF_forwarding_prep_0 + 50
5 Foundation 0x0113ab3e _encodeObject + 1076
6 Foundation 0x01145f89 +[NSKeyedArchiver archivedDataWithRootObject:] + 206
7 CoreData 0x0079ecb5 -[NSSQLiteConnection execute] + 2677
8 CoreData 0x007f0ebd -[NSSQLiteConnection updateRow:] + 365
9 CoreData 0x007efe64 -[NSSQLConnection performAdapterOperations:] + 180
10 CoreData 0x007efb0e -[NSSQLCore _performChangesWithAdapterOps:] + 494
11 CoreData 0x007ee5ea -[NSSQLCore performChanges] + 410
12 CoreData 0x007e8038 -[NSSQLCore saveChanges:] + 216
13 CoreData 0x007a6199 -[NSSQLCore executeRequest:withContext:error:] + 409
14 CoreData 0x0085670b -[NSPersistentStoreCoordinator executeRequest:withContext:error:] + 3691
15 CoreData 0x007de948 -[NSManagedObjectContext save:] + 712
16 BandManager 0x000320db -[GigDetailViewController setEditing:animated:] + 1259
17 UIKit 0x00a17d1e -[UIViewController(UINavigationControllerItem) _toggleEditing:] + 77
I have the ImageToDataTransformer interface defined in my ManagedObject, and I have the Image set to Transformable in the data model. Just when
[ManagedObjectContext save:&error]
in
- (void)setEditing:(BOOL)editing animated:(BOOL)animated 
is called it crashes. If anyone could help me out I would really appreciate it!
Post edited by nd049 on

Replies

  • zhoukaihangzhoukaihang Posts: 56Registered Users
    I got the same problem. Any clue? Thanks
    Why waste money on psychotherapy when you can listen to the B Minor Mass?
  • dljefferydljeffery Posts: 1,311iPhone Dev SDK Supporter, Registered Users
    When you say you have the same problem, what does that mean? Does your crash log look the same?

    At any rate, I would encourage you to not store images in your database, but to just store them in your Documents folder instead, and store references (filenames, or perhaps partial file paths) to them in your database instead. It keeps your database much tidier and also keeps memory usage down when querying your database.
    Recall It! Tag your notes. Tag your photos. Tag your thoughts. Tag your life.

    Recall It! for iPad
  • Naughty_OttselNaughty_Ottsel Posts: 255Registered Users
    My 2 cents, from my own experiences, crashes that happen when the context saves means that the object is not expected by the database, with that in mind I agree with dljeffery don't try to store a Image as is, even with transformable. I personally would set the object to be a Binary Data (NSData) then when you add the image to the database you would simply set the data to be the data of the image and load an image back with that data.

    e.g Adding to the Database

     

    myCoreDataObject.imageData = UIImagePNGRepresentation(myImage);

    //Do whatever else then call save.



    e.g loading from the database


    UIImage *myImage = [[UIImage alloc] initWithData:myCoreDataObject.imageData];

    //Load other objects etc and do whatever else we want to do.

Sign In or Register to comment.