由于NSUnknownKeyException

由于NSUnknownKeyException

本文介绍了由于NSUnknownKeyException,无法存储在RestKit的Core Data中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a web service that returns data as such:

{"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属性 - 任何人都看到我做错了什么?

I don't understand what is wrong given that each entity has an id property - anyone see what I am doing wrong?

更新:
类:

@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模型!

It would help if I hadn't removed the CoreData model from my application!

它仍然不工作,不同的错误 - 我将关闭此问题。

It is still not working but with a different error - I will close this issue.

这篇关于由于NSUnknownKeyException,无法存储在RestKit的Core Data中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 14:44