由于 NSUnknownKeyException,无法从 RestKit 存储核心数据
Posted
技术标签:
【中文标题】由于 NSUnknownKeyException,无法从 RestKit 存储核心数据【英文标题】:Unable to store in Core Data from RestKit because of NSUnknownKeyException 【发布时间】:2012-06-05 13:58:21 【问题描述】:我有一个返回数据的网络服务:
"facebook_friends":["name":"Jennifer","id":"38493","name":"Sarah","id":"363",
这是我的代码:
RKManagedObjectStore* objectStore = [RKManagedObjectStore objectStoreWithStoreFilename:@"MyApp.sqlite"];
RKObjectManager* objectManager = [RKObjectManager objectManagerWithBaseURLString:@"http://192.168.85.128"];
objectManager.objectStore = objectStore;
RKManagedObjectMapping *friendMapping = [RKManagedObjectMapping mappingForClass:[Friend class] inManagedObjectStore:objectStore];
[friendMapping mapKeyPath:@"id" toAttribute:@"facebook_id"];
[friendMapping mapKeyPath:@"name" toAttribute:@"name"];
friendMapping.primaryKeyAttribute = @"facebook_id";
[[RKObjectManager sharedManager].mappingProvider setMapping:friendMapping forKeyPath:@"facebook_friends"];
[objectManager loadObjectsAtResourcePath:@"/sharing/friends_facebook.json" delegate:self];
但我收到此错误:
2012-06-05 09:53:14.098 promobust[10071:1520b] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<NSManagedObject 0x6d153b0> setValue:forUndefinedKey:]: the entity Friend is not key value coding-compliant for the key "facebook_id".'
鉴于每个实体都有一个 id 属性,我不明白出了什么问题 - 任何人都知道我做错了什么吗?
更新: 朋友班:
@interface Friend : NSManagedObject
@property (nonatomic, retain) NSNumber* facebook_id;
@property (nonatomic, retain) NSString* name;
- (BOOL)validateName:(id *)ioValue error:(NSError **)outError;
@end
@implementation Friend
// We use @dynamic for the properties in Core Data
@dynamic facebook_id;
@dynamic name;
- (BOOL)validateName:(id *)ioValue error:(NSError **)outError
NSLog(@"Validating Friend");
return YES;
谢谢!
【问题讨论】:
我已通过更新将 Friend 类添加到问题中。我应该如何在文本中显示我的核心数据模型?此外,我将努力在未来接受所有好的回应,并且我会及时回去做同样的事情。再次感谢。 【参考方案1】:如果我没有从我的应用程序中删除 CoreData 模型会有所帮助!
它仍然无法正常工作,但出现了不同的错误 - 我将关闭此问题。
【讨论】:
以上是关于由于 NSUnknownKeyException,无法从 RestKit 存储核心数据的主要内容,如果未能解决你的问题,请参考以下文章
由于 NSUnknownKeyException,无法从 RestKit 存储核心数据
由于未捕获的异常“NSUnknownKeyException”而终止应用程序此类不符合键 .img 的键值编码
iOS5 和 XCode4 错误 - 由于未捕获的异常“NSUnknownKeyException”而终止应用程序
错误:由于未捕获的异常'NSUnknownKeyException'而终止应用,原因:'[ 的setValue:forUndefinedKey:]