Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 07-03-2011, 06:46 PM   #1 (permalink)
Registered Member
 
Join Date: Jan 2010
Location: MA
Posts: 126
nd049 is on a distinguished road
Default Images in CoreData

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:
Quote:
[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
Code:
[ManagedObjectContext save:&error]
in
Code:
- (void)setEditing:(BOOL)editing animated:(BOOL)animated
is called it crashes. If anyone could help me out I would really appreciate it!

Last edited by nd049; 07-03-2011 at 06:49 PM.
nd049 is offline   Reply With Quote
Old 03-21-2012, 01:15 AM   #2 (permalink)
Registered Member
 
zhoukaihang's Avatar
 
Join Date: Jan 2009
Posts: 56
zhoukaihang is on a distinguished road
Default

I got the same problem. Any clue? Thanks
__________________
Why waste money on psychotherapy when you can listen to the B Minor Mass?
zhoukaihang is offline   Reply With Quote
Old 03-21-2012, 03:45 AM   #3 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
Join Date: Jan 2010
Location: Issaquah, WA
Age: 42
Posts: 1,244
dljeffery is on a distinguished road
Default

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

http://www.dljeffery.com
dljeffery is offline   Reply With Quote
Old 03-22-2012, 07:42 AM   #4 (permalink)
Registered Member
 
Naughty_Ottsel's Avatar
 
Join Date: Aug 2008
Location: Gillingham, Dorset, UK
Age: 19
Posts: 218
Naughty_Ottsel is on a distinguished road
Send a message via MSN to Naughty_Ottsel
Default

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

Code:
 

myCoreDataObject.imageData = UIImagePNGRepresentation(myImage);

//Do whatever else then call save.
e.g loading from the database
Code:
UIImage *myImage = [[UIImage alloc] initWithData:myCoreDataObject.imageData];

//Load other objects etc and do whatever else we want to do.
__________________
Follow me on Twitter
Naughty_Ottsel is offline   Reply With Quote
Reply

Bookmarks

Tags
core data entities, uiimage

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 350
9 members and 341 guests
apatsufas, chemistry, lendo, leostc, Leslie80, lzwasyc, MarkC, SamorodovAlex, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,664
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Leslie80
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:33 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0