I'm trying to store data of a custom type with core data. My class (friendItem) has one property (friend) of type NSData, to store it.
After archiving every elements of my array of type KNSelectorItem to NSData, I store them as "friend" in friendItem. But when I want to unarchive every elements of my array to read the information as KNSelectorItem objects, I get this error:
-[FriendItems bytes]: unrecognized selector sent to instance 0x10a637dc0
Code that might help:
HomeViewController.m
-(void)selector:(KNMultiItemSelector *)selector didFinishSelectionWithItems:(NSArray *)selectedItems
{
for (KNSelectorItem * i in selectedItems) {
NSLog(@"ID: %@ NAME: %@", i.selectValue, i.displayValue);
NSData *friendtosave = [NSKeyedArchiver archivedDataWithRootObject:i];
[MagicalRecord saveWithBlock:^(NSManagedObjectContext *localContext) {
FriendItems *friend = [FriendItems MR_createEntityInContext:localContext];
friend.friend = friendtosave;
}];
}
In ViewDidLoad of HomeViewController.m
NSArray *friendsdata = [FriendItems MR_findAll];
NSLog(@"friends saved as data %@", friendsdata);
NSMutableArray *unarchievedFriends = [NSMutableArray array];
for (NSData *i in friendsdata)
{
KNSelectorItem *friendDecrypted = [NSKeyedUnarchiver unarchiveObjectWithData:i];
[unarchievedFriends addObject:friendDecrypted]; // THIS IS WHERE IT FAILS WHEN CHECKING WITH BREAKPOINTS
NSLog(@"friend decrypted : %@", friendDecrypted.displayValue);
}
What did I do wrong ? What did I miss ?
PS: I'm using Magical Record to manage my core data.
Thanks.