My iPhone game crashed whilst on the device and I am attempting to understand what happened.
Every time a user exits the game screen it will send a message to the HomePageController (my top level controller) telling it to save the user data. This works fine all the time except for in this particular instance. The exception thrown seems to state that HomePageController did not recognize the saveUserData selector but I can't see how that can happen as that function is definitely in that controller and it works the rest of the time.
Can anyone offer any advice?
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x00000000, 0x00000000
Crashed Thread: 0
Last Exception Backtrace:
0 CoreFoundation 0x3756a88f __exceptionPreprocess + 163
1 libobjc.A.dylib 0x35a70259 objc_exception_throw + 33
2 CoreFoundation 0x3756da9b -[NSObject doesNotRecognizeSelector:] + 175
3 CoreFoundation 0x3756c915 ___forwarding___ + 301
4 CoreFoundation 0x374c7650 _CF_forwarding_prep_0 + 48
5 P------k 0x0000ebe1 -[HomePageController saveUserData] (HomePageController.m:125)
6 P------k 0x00008a0b -[RootViewController viewDidAppear:] (RootViewController.m:102)
Line 125 in HomePageController.m:
- (void)saveUserData{
NSString *documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES) objectAtIndex:0];
//10x10
{
NSMutableDictionary *dict = [[[NSMutableDictionary alloc] init] autorelease];
for (int i = 0; i < _puzzles10x10.count; i++){
LevelData *currentPuzzle = [_puzzles10x10 objectAtIndex:i];
/*(line 125)*/ [dict setObject:[currentPuzzle getPuzzleUserData] forKey:currentPuzzle.title];
}
[dict writeToFile:[documentsPath stringByAppendingPathComponent:#"userdata.dat"] atomically:YES];
}
// more here
}
If currentPuzzle doesn't recognize the selector getPuzzleUserData then the problem is one of these two:
LevelData does not define a method getPuzzleUserData.
currentPuzzle is not an instance of LevelData
So check if the method is actually defined in the class LevelData and not in HomePageController and that when you add items to _puzzles10x10 they are actually instances of LevelData.
To debug further, split your code into as many lines as possible (one instruction per line), add a lot of NSLog calls and see what happens:
NSLog(#"_puzzles10x10: %#", _puzzles10x10);
for (int i = 0; i < _puzzles10x10.count; i++){
LevelData *currentPuzzle = [_puzzles10x10 objectAtIndex:i];
NSLog(#"currentPuzzle#%d: %#", i, currentPuzzle);
UserData *userData = [currentPuzzle getPuzzleUserData]; // change UserData to the correct t class
NSLog(#"userData#%d: %#", i, userData);
NSString *key = currentPuzzle.title;
NSLog(#"key#%d: %#", i, key);
[dict setObject:userData forKey:key];
}
From log it is clear that, you are invoking a method in the object which was not really exist.
(2 CoreFoundation 0x3756da9b -[NSObject doesNotRecognizeSelector:] + 175)
I think the data type of '_puzzles10x10' is changed to some other type by making mistakes in code.
Related
I observed no crash in my simulator runs but it is consistently happening on my iPhone (iOS 5.1) and iPad (iOS 6.1).
After much effort I symbolicated the crash to point the erroneous line in my code - here this symbolicated log goes:
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Crashed Thread: 12
Last Exception Backtrace:
0 CoreFoundation 0x342fd29e 0x3423b000 + 795294
1 libobjc.A.dylib 0x3c17197a 0x3c169000 + 35194
2 CoreFoundation 0x342fd1c0 0x3423b000 + 795072
3 CoreFoundation 0x3425e864 0x3423b000 + 145508
4 MyApp 0x0011626c __55-[MSCollectionViewController updateUI:]_block_invoke (MSCollectionViewController.m:385)
5 libdispatch.dylib 0x3c58911a 0x3c587000 + 8474
6 libdispatch.dylib 0x3c58d95c 0x3c587000 + 26972
7 libdispatch.dylib 0x3c58dabc 0x3c587000 + 27324
8 libsystem_c.dylib 0x3c5bda0c 0x3c5b7000 + 27148
9 libsystem_c.dylib 0x3c5bd8a0 0x3c5b7000 + 26784
As anyone can guess, the error is on Line#385 of my MSCollectionViewController.m file. However I am still unable to see what could cause such a crash, as it runs fine on simulator.
UPDATED CODE:
Note that now it is crashing at [m_photoArray addObject:photoDetailDict];
I added m_photoArray (NSMutableArray) initialization for reference which I am doing on main thread.
Here is my code, including the problematic line # 385 as comment:
__block NSString * flickrPhotoArrayPath = [Commons getFlickrJSONPathForMuseumURI:argURI];
if (m_photoArray)
{
[m_photoArray removeAllObjects];
}
else
{
m_photoArray = [[NSMutableArray alloc] init];
}
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0),
^{
NSArray *arrayFromFlickrJSON = [NSArray arrayWithContentsOfFile:flickrPhotoArrayPath];
if (!arrayFromFlickrJSON || [arrayFromFlickrJSON count]==0)
return;
if (bViewVisible)
{
[SVProgressHUD showWithStatus:#"Fetching Photos" maskType:SVProgressHUDMaskTypeBlack];
}
for (id photo in arrayFromFlickrJSON)
{
NSDictionary * dict = (NSDictionary *)photo;
NSMutableDictionary * photoDetailDict = [dict mutableCopy];
NSString * filePath = [photoDetailDict objectForKey:#"photoFilePath"];
UIImage *image = [UIImage imageWithContentsOfFile:filePath];
[photoDetailDict setObject:image forKey:#"photoImage"];
//AND HERE GOES THE CRASH!!!
[m_photoArray addObject:photoDetailDict]; //Line 385
}
dispatch_async(dispatch_get_main_queue(), ^{
if ([SVProgressHUD isActive])
[SVProgressHUD dismiss];
//More code to update UI
});
});
Here goes my 2 questions:
What is it in NSMutableDictionary setObject that I am seeing this crash?
Why don't I observe it with same set of data on my simulator?
UPDATE:
Instantly found glitch in my code:
The issue maybe in [photo mutableCopy]; - photo is of id type, not NSDictionary. I need to cast it to NSDictionary first before performing mutableCopy.
The major question still remains is - why simulator allows it?
Heck, why even compiler allows it?
I have this bit of code relating to my in app purchases for an SKProductRequest:
SKProductsRequest *request= [[SKProductsRequest alloc] initWithProductIdentifiers:...
request.delegate = self;
[request start];
[request release];
One of my users is getting a crash on an iPod4 and I think it might be from this, however, all other devices are able to run this code OK. Should request be saved in a property while its loading, could that be the issue? I would think with [request start], that request would be retained somewhere else.
Here is the crash log:
Last Exception Backtrace:
0 CoreFoundation 0x3275229e __exceptionPreprocess + 158
1 libobjc.A.dylib 0x3a3c597a objc_exception_throw + 26
2 CoreFoundation 0x3269ce88 -[__NSArrayI objectAtIndex:] + 160
3 AppsHappens Lite 0x000e43ac 0xd8000 + 50092
4 StoreKit 0x3450c22e __34-[SKProductsRequest _handleReply:]_block_invoke_0 + 378
5 libdispatch.dylib 0x3a7dd11a _dispatch_call_block_and_release + 6
6 libdispatch.dylib 0x3a7dc4b2 _dispatch_client_callout + 18
7 libdispatch.dylib 0x3a7dddc6 _dispatch_main_queue_callback_4CF$VARIANT$up + 222
8 CoreFoundation 0x32725f36 __CFRunLoopRun + 1286
9 CoreFoundation 0x32698eb8 CFRunLoopRunSpecific + 352
10 CoreFoundation 0x32698d44 CFRunLoopRunInMode + 100
11 GraphicsServices 0x362492e6 GSEventRunModal + 70
12 UIKit 0x345ae2fc UIApplicationMain + 1116
13 AppsHappens Lite 0x000e3a8e 0xd8000 + 47758
14 AppsHappens Lite 0x000dadb4 0xd8000 + 11700
Updated: A lot of folks below are saying that it's an array out of bounds error and I think they're right. Strange thing is though, it appears the product request is coming back successfully, and it's called ing [self loadFullVersionPrice] which simply extracts the price for one of my products. When it tries to retrieve the Full Version product from the products array, I think that's when it crashes. Is it possible the app store would only return some of my products and not all of them? Or some issue with an iPod4?
- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response
{
self.products = response.products;
if (self.products)
{
[self loadFullVersionPrice];
}
}
- (void) loadFullVersionPrice
{
SKProduct *product = [[self.products objectAtIndex:[self.products count]-1] retain];
NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
[numberFormatter setFormatterBehavior:NSNumberFormatterBehavior10_4];
[numberFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
[numberFormatter setLocale:product.priceLocale];
self.fullVersionPrice = [numberFormatter stringFromNumber:product.price];
[numberFormatter release];
[product release];
}
Also, the iPod Touch 4 in question is jail broken.
Three reasons why this was occurring:
1) The user was on a jail broken phone
2) The version of my app he was installing was an ad hoc release
3) He was trying to access in app purchase
Apparently, jail broken phones are unable to access the sandbox (which is accessed when you try to do an app purchase on an ad hoc distribution).
I'm occasionally getting this crash, which is very hard to reproduce:
0 CoreFoundation 0x39ff73e2 __exceptionPreprocess + 158
1 libobjc.A.dylib 0x3905095e objc_exception_throw + 26
2 CoreFoundation 0x39ffaf2c -[NSObject(NSObject) doesNotRecognizeSelector:] + 180
3 CoreFoundation 0x39ff9648 ___forwarding___ + 388
4 CoreFoundation 0x39f51204 _CF_forwarding_prep_0 + 20
5 Foundation 0x32914bec -[NSDictionary(NSKeyValueCoding) valueForKey:] + 28
6 MyAppName 0x00032112 -[myViewController stopPlayersWithVolume:] (myViewController.m:151)
From this code:
- (void)stopPlayersWithVolume:(double)volume
{
for (NSString *file in players)
{
AVAudioPlayer *player = [players valueForKey:file];
if (player.volume == volume || volume == 0)
[player stop];
}
}
players is an NSMutableDictionary property, accessed without self. because I don't believe it's needed with ARC. The keys are filenames (e.g. "mysound.mp3") and the values are AVAudioPlayer objects.
Is the stack trace saying that the parameter file I'm passing to [NSMutableDictionary valueForKey] is not actually an NSString, and hence the unrecognised selector? It is always an NSString in the debugger, as you'd expect as it comes from a fast enumeration through the dictionary, but the crash never occurs in the debugger.
My only thought is that there's a threading issue corrupting the dictionary. The code above is being fired by an NSTimer but that's just a message via the run loop, not a separate thread, so I believe there should be no need to worry about cross-thread access?
Any suggestions appreciated. Sorry to just dump this out but I'm stuck.
Edit:
The players dictionary is allocated in viewDidLoad thus:
players = [[NSMutableDictionary alloc] init];
And declared as follows:
#property (retain, nonatomic) NSMutableDictionary *players;
And synthesised as follows:
#synthesize players;
It's likely that your players dictionary or its contents are being deallocated while you're iterating through them. Can you turn on NSZombies and try to reproduce the crash in the debugger? It will give you more information about what object is being deallocated.
The code to allocate the dictionary (and set up the audio stuff) looked like this:
NSError *error = [[NSError alloc] init];
NSArray *names = [fm contentsOfDirectoryAtPath:resourcePath error:&error];
players = [[NSMutableDictionary alloc] init];
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient error:&error];
[[AVAudioSession sharedInstance] setActive:YES error:&error];
I must have copied and pasted it from somewhere, because that use of NSError is wrong, as far as I know, though hardly likely to cause a problem. I changed the code to this:
NSArray *names = [fm contentsOfDirectoryAtPath:resourcePath error:nil];
players = [[NSMutableDictionary alloc] init];
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient error:nil];
[[AVAudioSession sharedInstance] setActive:YES error:nil];
And the problem goes away, it appears. Can't be 100% sure but I can reproduce the crash within 10 attempts with the former code and never with the latter. No idea why.
I have an iphone app that when the user clicks a row in a uitable, it takes the row value and downloads some data from the web to populate the next view. However if the user switches back to the first view when the data is being downloaded the app crashes. I think i've found the problem but need some help fixing it:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSManagedObject *selectedObject = [[self fetchedResultsController] objectAtIndexPath:indexPath];
BlogRssParser *blogRss = [[BlogRssParser alloc] init];
blogRss.terms = [[selectedObject valueForKey:#"data"] description];
RssFunViewController *rssFun = [[RssFunViewController alloc] initWithNibName:#"RssFunViewController" bundle:nil];
rssFun.rssParser = blogRss;
[blogRss release];
[self.navigationController pushViewController:rssFun animated:YES];
rssFun.navigationItem.title=blogRss.terms;
[rssFun release];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
So where it says [self.navigationController pushViewController:rssFun animated:YES]; this is where it crashes because once it finishes the download this is the next line of code and it can push a view if its not on the right screen if that makes any sense!? Thanks for any advice anyway!
BlogRssParser:
-(BOOL)fetchAndParseRss{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
//To suppress the leak in NSXMLParser
[[NSURLCache sharedURLCache] setMemoryCapacity:0];
[[NSURLCache sharedURLCache] setDiskCapacity:0];
NSString *urlTerm = terms;
urlTerm = [urlTerm stringByReplacingOccurrencesOfString:#" " withString:#"+"];
urlTerm = [urlTerm stringByReplacingOccurrencesOfString:#"\t" withString:#""];
urlTerm = [urlTerm stringByReplacingOccurrencesOfString:#"&" withString:#""];
urlTerm = [urlTerm stringByReplacingOccurrencesOfString:#"'" withString:#""];
urlTerm = [urlTerm stringByReplacingOccurrencesOfString:#"-" withString:#""];
urlTerm = [urlTerm stringByReplacingOccurrencesOfString:#"_" withString:#""];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:#"xxxxxxxxxxxxx/app.php?s=%#", urlTerm]];
NSLog(#"%#", url);
BOOL success = NO;
NSXMLParser *parser = [[NSXMLParser alloc] initWithContentsOfURL:url];
[parser setDelegate:self];
[parser setShouldProcessNamespaces:YES];
[parser setShouldReportNamespacePrefixes:YES];
[parser setShouldResolveExternalEntities:NO];
success = [parser parse];
[parser release];
[pool drain];
return success;
}
Console:
2010-12-06 19:15:09.826 Example[452:207] -[NSCFString processCompleted]: unrecognized selector sent to instance 0x6123d30
2010-12-06 19:15:09.855 Example[452:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString processCompleted]: unrecognized selector sent to instance 0x6123d30'
*** Call stack at first throw:
(
0 CoreFoundation 0x02664b99 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x027b440e objc_exception_throw + 47
2 CoreFoundation 0x026666ab -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x025d62b6 ___forwarding___ + 966
4 CoreFoundation 0x025d5e72 _CF_forwarding_prep_0 + 50
5 Foundation 0x000423ca __NSThreadPerformPerform + 251
6 CoreFoundation 0x02645faf __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
7 CoreFoundation 0x025a439b __CFRunLoopDoSources0 + 571
8 CoreFoundation 0x025a3896 __CFRunLoopRun + 470
9 CoreFoundation 0x025a3350 CFRunLoopRunSpecific + 208
10 CoreFoundation 0x025a3271 CFRunLoopRunInMode + 97
11 GraphicsServices 0x02f4300c GSEventRunModal + 217
12 GraphicsServices 0x02f430d1 GSEventRun + 115
13 UIKit 0x002d1af2 UIApplicationMain + 1160
14 Example 0x0000244a main + 84
15 Example 0x000023ed start + 53
)
terminate called after throwing an instance of 'NSException'
unrecognized selector means that you've attempted to send a message to an object that doesn't know how to handle it.
For example, suppose you had a class AlienParser and it had two methods: land and probe. You create an instance of it called myParser, and then tried to call [myParser destroyAllHumans]. The resulting object wouldn't know what to do, and you'd get an exception thrown. It compiles because you can send any message to anything with Obj-C, because at runtime it may know how to handle it even if the compiler couldn't detect so.
Somewhere (the hex is your clue, it doesn't show a full backtrace) you've got some code calling another object with a message it just plain doesn't support. It's probably worth mentioning that ANY message to nil does nothing and returns nil so you've obviously got an actual object there you are sending messages to.
Have you tried downloading the XML in a background thread? This may alleviate some of the issues as the main thread won't be blocked. You should be able to push on the RssFunViewController while the XML is/being downloaded.
In my app, I am trying to save and retrieval of an image in core data. I am able to save an image successfully after convention of UIimage into NSData, But when I am trying to get an image as NSData it shows output as given below,
case 1: When trying to display as a string from DB.
<Event: 0x5b5d610> (entity: Event; id: 0x5b5ce30 <x-coredata://F51BBF1D-6484-4EB6-8583-147E23D9FF7B/Event/p1> ; data: <fault>)
case 2: When trying to display as Data
[Event length]: unrecognized selector sent to instance 0x5b3a9c0
2010-07-28 19:11:59.610 IMG_REF[10787:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Event length]: unrecognized selector sent to instance 0x5b3a9c0'
My code,
to save:
NSManagedObjectContext *context = [self managedObjectContext];
newsObj = [NSEntityDescription insertNewObjectForEntityForName:#"Event" inManagedObjectContext:context];
NSURL *url = [NSURL URLWithString:#"http://www.cimgf.com/images/photo.PNG"];
NSData *data = [[NSData alloc] initWithContentsOfURL:url];
uiImage = [UIImage imageWithData:data];
NSData * imageData = UIImagePNGRepresentation(uiImage);
[newsObj setValue:imageData forKey:#"imgPng"];
NSError *error;
#try{
if (managedObjectContext != nil) {
if (![managedObjectContext save:&error]) {
NSLog(#"Unresolved error %#, %#", error, [error userInfo]);
NSString * infoString = [NSString stringWithFormat:#"Please check your connection and try again."];
UIAlertView * infoAlert = [[UIAlertView alloc] initWithTitle:#"Database Connection Error" message:infoString delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[infoAlert show];
[infoAlert release];
}
}
}#catch (NSException *exception) {
NSLog(#"inside exception");
}
to retrieve,
NSManagedObjectContext *context = [self managedObjectContext];
NSFetchRequest * fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity1 = [NSEntityDescription entityForName:#"Event" inManagedObjectContext:context];
[fetchRequest setEntity:entity1];
NSError *error;
NSArray * array = [self.managedObjectContext executeFetchRequest:fetchRequest error:&error];
if (array == nil) {
NSLog(#"Testing: No results found");
}else {
NSLog(#"Testing: %d Results found.", [array count]);
}
NSData * dataBytes = [[array objectAtIndex:0] data];
image = [UIImage imageWithData:dataBytes];
[fetchRequest release];
}
#catch (NSException *exception) {
NSLog(#"inside exception");
}
Error:
Testing: 3 Results found.
2010-07-28 23:27:51.343 IMG_REF[11657:207] -[Event data]: unrecognized selector sent to instance 0x5e22ce0
2010-07-28 23:27:51.344 IMG_REF[11657:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Event data]: unrecognized selector sent to instance 0x5e22ce0'
*** Call stack at first throw:
(
0 CoreFoundation 0x02566919 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x026b45de objc_exception_throw + 47
2 CoreFoundation 0x0256842b -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x024d8116 ___forwarding___ + 966
4 CoreFoundation 0x024d7cd2 _CF_forwarding_prep_0 + 50
5 IMG_REF 0x00003b06 -[IMG_REFViewController showAction] + 353
6 UIKit 0x002bae14 -[UIApplication sendAction:to:from:forEvent:] + 119
7 UIKit 0x004c214b -[UIBarButtonItem(UIInternal) _sendAction:withEvent:] + 156
8 UIKit 0x002bae14 -[UIApplication sendAction:to:from:forEvent:] + 119
9 UIKit 0x003446c8 -[UIControl sendAction:to:forEvent:] + 67
10 UIKit 0x00346b4a -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
11 UIKit 0x003456f7 -[UIControl touchesEnded:withEvent:] + 458
12 UIKit 0x002de2ff -[UIWindow _sendTouchesForEvent:] + 567
13 UIKit 0x002c01ec -[UIApplication sendEvent:] + 447
14 UIKit 0x002c4ac4 _UIApplicationHandleEvent + 7495
15 GraphicsServices 0x02dccafa PurpleEventCallback + 1578
16 CoreFoundation 0x02547dc4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
17 CoreFoundation 0x024a8737 __CFRunLoopDoSource1 + 215
18 CoreFoundation 0x024a59c3 __CFRunLoopRun + 979
19 CoreFoundation 0x024a5280 CFRunLoopRunSpecific + 208
20 CoreFoundation 0x024a51a1 CFRunLoopRunInMode + 97
21 GraphicsServices 0x02dcb2c8 GSEventRunModal + 217
22 GraphicsServices 0x02dcb38d GSEventRun + 115
23 UIKit 0x002c8b58 UIApplicationMain + 1160
24 IMG_REF 0x00002aac main + 102
25 IMG_REF 0x00002a3d start + 53
)
terminate called after throwing an instance of 'NSException'
Note: Above error is coming when going to execute NSData * dataBytes = [[array objectAtIndex:0] data]; line.
Data Model http://www.freeimagehosting.net/uploads/7c286931cc.png
I spent a lot of time with this. Please help me out!
Not sure if you've gotten this straightened out yet, but I am able to save/retrieve UIImage objects in Core Data as follows:
To save:
NSData *imageData = UIImagePNGRepresentation(yourUIImage);
[newManagedObject setValue:imageData forKey:#"image"];
and to load:
NSManagedObject *selectedObject = [[self fetchedResultsController] objectAtIndexPath:indexPath];
UIImage *image = [UIImage imageWithData:[selectedObject valueForKey:#"image"]];
[[newCustomer yourImageView] setImage:image];
Hope this helps. I am using a UITableView with Core Data and pulling the image from the database in my tableView:didSelectRowAtIndexPath: method.
Here's the proper solution that works very well.
1) Storing UIImage with Core Data:
NSData* coreDataImage = [NSData dataWithData:UIImagePNGRepresentation(delegate.dancePhoto)];
Make sure that "coreDataImage" is of type NSData. You have to set type to "Binary data" for "coreDataImage" in your model.
2) Retrieving UIImage from Core Data:
UIImage* image = [UIImage imageWithData:selectedDance.danceImage];
That's all there's to it, works great.
When you retrieve the image, you're performing the fetch request and storing the results in the variable array, meaning array holds an NSArray of Event objects. Then, later, you assign:
dataBytes = [array objectAtIndex:0];
This means that dataBytes, which you declared as NSData, is now actually an instance of Event. Then when you go to initialize the image, part of the implementation of imageWithData: calls length on what it expects to be your NSData object, but is actually an Event object, hence the error message.
You should adjust your code to read:
dataBytes = [[array objectAtIndex:0] imgPng];
That way, you're getting the first Event object out of the array, then fetching its imgPng property (an instance of NSData, which is what you want).
As a side note, your declaration of dataBytes using the alloc-init on the line above may be extraneous, since you change dataBytes to be the data from your Event immediately afterwards.
The Solution I used was to create the category bellow. You just need it in your project for it to work. Using this storing images works just like you where storing an NSData
UIImage+NSCoding.h
#interface UIImage (UIImage_NSCoding) <NSCoding>
- (void)encodeWithCoder:(NSCoder *)aCoder;
- (id)initWithCoder:(NSCoder *)aDecoder;
#end
UIImage+NSCoding.m
#import "UIImage+NSCoding.h"
#implementation UIImage (UIImage_NSCoding)
- (void)encodeWithCoder:(NSCoder *)aCoder
{
NSData *imageData = UIImagePNGRepresentation(self);
[aCoder encodeDataObject:imageData];
}
- (id)initWithCoder:(NSCoder *)aDecoder
{
[self autorelease];
NSData* imageData = [aDecoder decodeDataObject];
self = [[UIImage alloc] initWithData:imageData];
return self;
}
#end
This sample code has example how to store UIImage in Core Data:
https://developer.apple.com/library/ios/#samplecode/PhotoLocations/Introduction/Intro.html