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 中确实有一个池实体。

我还可以在哪里寻找此错误的原因?

4

1 回答 1

1

id属性添加到您的Pool实体。
注意:命名属性是可行的id,但我建议将其更改为不是 Objective-C 关键字的东西。

于 2013-05-14T03:56:13.577 回答