如何确定“未找到属性”异常的原因?

时间:2013-05-14 00:55:22

标签: ios ios6 restkit

我按照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"];

在第100行(if (!attribute) [NSException raise:NSInvalidArgumentException format:@"Invalid attribute '%@': no attribute was found for the given name in the '%@' entity.", attributeOrName, [entity name]];)的RKEntityMapping.m中抛出了异常,这是RKArrayOfAttributesForEntityFromAttributesOrNames的一部分。

当我po [entity name]它说“Pool”但我的.xcdatamodeld中有一个Pool实体。

我还能在哪里查找此错误的原因?

1 个答案:

答案 0 :(得分:1)

id实体添加Pool媒体资源 注意:命名属性id可行,但我建议将其更改为不是Objective-C关键字的内容。