I can not save the image using nsuserdefaults and crashed my application, and also used the user class UserInfo, which used
-(void)encodeWithCoder:(NSCoder *)encoder { NSData *imageData = UIImagePNGRepresentation(categoryImage); [encoder encodeObject:categoryName forKey:@"name"]; [encoder encodeObject:imageData forKey:@"image"]; }
- (id) initWithCoder: (NSCoder *) decoder and userInfo.categoryImage is a UIImage variable.
reason: '- [UIImage encodeWithCoder:]: unrecognized selector sent to instance 0x7676a70'
userInfo = [[UserInfo alloc] init]; userInfo.categoryName = categoryName.text; NSLog(@"Category Name:--->%@",userInfo.categoryName); userInfo.categoryImage = image; appDelegate.categoryData = [[NSMutableDictionary dictionaryWithObjectsAndKeys: userInfo.categoryName, @"name",userInfo.categoryImage,@"image", nil] mutableCopy]; [appDelegate.categories addObject:appDelegate.categoryData]; NSLog(@"Category Data:--->%@",appDelegate.categories); [appDelegate.categories addObject:userInfo.categoryName]; [appDelegate.categories addObject:userInfo.categoryImage]; [self saveCustomObject:userInfo.categoryName]; [self saveCustomObject:userInfo.categoryImage]; -(void)saveCustomObject:(UserInfo *)obj { appDelegate.userDefaults = [NSUserDefaults standardUserDefaults]; NSData *myEncodedObject = [NSKeyedArchiver archivedDataWithRootObject:obj]; [appDelegate.userDefaults setObject:myEncodedObject forKey:@"myEncodedObjectKey"]; }
So help me how can I store and retrieve uiimage using nsusedefaults ???
source share