1
的RestKit我有一個返回數據作爲這樣一個Web服務:無法在覈心數據存儲從因爲NSUnknownKeyException
{"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類添加到問題中。我應該如何在文本中顯示我的核心數據模型?另外,我將努力接受所有未來的好迴應,並且會及時回去做同樣的事情。再次感謝。 – Eric