由于NSUnknownKeyException,无法从RestKit存储在Core Data中

我有一个返回数据的Web服务:

{"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: '[ 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; } 

谢谢!

如果我没有从我的应用程序中删除CoreData模型,这将有所帮助!

它仍然没有工作,但有一个不同的错误 – 我将关闭这个问题。