2013-05-14 48 views
1

我跟着RestKit文档中的所有步骤将其添加到一个项目,但是当我尝试启动我的应用程序是在这一行application:application didFinishLaunchingWithOptions:停止:如何识别“找不到属性”异常的原因?

entityMapping.identificationAttributes = @[@"_id"]; 

在此之前的代码是:

NSURL *modelURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"MyModel" ofType:@"momd"]]; 
NSManagedObjectModel *managedObjectModel = [[[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL] mutableCopy]; 
RKManagedObjectStore *managedObjectStore = [[RKManagedObjectStore alloc] initWithManagedObjectModel:managedObjectModel]; 

// Init the Core Data stack 
[managedObjectStore createPersistentStoreCoordinator]; 

NSPersistentStore __unused *persistentStore = [managedObjectStore addInMemoryPersistentStore:&error]; 
NSAssert(persistentStore, @"Faild to add persistent store: %@", error); 

[managedObjectStore createManagedObjectContexts]; 

// Set the default shared store instance 
[RKManagedObjectStore setDefaultStore:managedObjectStore]; 

// Configure the object manager 
RKObjectManager *objectManager = [RKObjectManager managerWithBaseURL:[NSURL URLWithString:@"http://localhost:9090"]]; 
objectManager.managedObjectStore = managedObjectStore; 

[RKObjectManager setSharedManager:objectManager]; 

RKEntityMapping *entityMapping = [RKEntityMapping mappingForEntityForName:@"Pool" inManagedObjectStore:managedObjectStore]; 
[entityMapping addAttributeMappingsFromDictionary:@{ 
@"id":   @"_id", 
@"about_url": @"aboutURL", 
@"closed":  @"closed", 
@"created_on": @"createdOn" 
}]; 
entityMapping.identificationAttributes = @[@"_id"]; 

例外是越来越抛出RKEntityMapping.m上线100(if (!attribute) [NSException raise:NSInvalidArgumentException format:@"Invalid attribute '%@': no attribute was found for the given name in the '%@' entity.", attributeOrName, [entity name]];),这是RKArrayOfAttributesForEntityFromAttributesOrNames一部分。

当我po [entity name]它说:“游泳池”,但我有我的.xcdatamodeld池实体。

我可能会在别的地方寻找这个错误的原因是什么?

+0

为什么'@ [@“_ id”]'而不是'@ [@“id”]'? – 2013-05-14 02:46:21

+0

我最初有@ [@“id”],但JSON中的键是'_id',所以我想这可能是问题所在,并改变了这一行。 – 2013-05-14 02:52:31

+1

“Pool”实体中的“id”属性名称是什么? – 2013-05-14 02:54:31

回答

1

id属性添加到您的Pool实体。
注:命名属性id会的工作,但我会建议其更改的东西,不是一个Objective-C关键字。