2013-05-14 46 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關鍵字。