KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
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, NSMa
Tags (comma-separated)
Save Edits
Cancel