【发布时间】:2013-09-30 20:13:58
【问题描述】:
我正在从 Web 服务中获取裸 JSON 数组中的一些 URL,如下所示:
[
"https://server1.com",
"https://server2.com"
]
我想将这些映射到单独的核心数据实体,但遇到断言失败:
I restkit.network:RKObjectRequestOperation.m:180 GET 'https://server-test.com/Client/Endpoints'
*** Assertion failure in NSDictionary *RKEntityIdentificationAttributesForEntityMappingWithRepresentation(RKEntityMapping *__strong, NSDictionary *__strong)(), /Users/jonukas/MyApp/Pods/RestKit/Code/CoreData/RKManagedObjectMappingOperationDataSource.m:83
An uncaught exception was raised
Expected a dictionary representation
FWIW,在RKManagedObjectMappingOperationDataSource.m:83 上设置断点表明应该是NSDictionary 的表示实际上是RKMappingSourceObject。
这是我制作的映射:
RKEntityMapping *mapping = [RKEntityMapping mappingForEntityForName:@"MyURL"
inManagedObjectStore:self.manager.managedObjectStore];
[mapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:nil
toKeyPath:@"url"]];
RKResponseDescriptor *descriptor = [RKResponseDescriptor responseDescriptorWithMapping:mapping
method:RKRequestMethodGET
pathPattern:@"Client/Endpoints"
keyPath:nil
statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
[self.manager addResponseDescriptor:descriptor];
我的实体只有一个可转换类型的属性 (url)。这是NSManagedObject 子类:
@interface MyURL : NSManagedObject
@property (nonatomic, retain) id url;
@end
是我的映射不正确还是我的实体描述/对象模型有问题(请原谅,我刚开始使用 Core Data)?
更新:我尝试设置标识属性,但似乎没有帮助:
[mapping setIdentificationAttributes:@[@"url"]];
为RestKit/ObjectMapping 启用跟踪日志记录会导致:
D restkit.object_mapping:RKMapperOperation.m:377 Executing mapping operation for representation: (
"https://server1.com",
"https://server2.com"
)
and targetObject: (null)
T restkit.object_mapping:RKMapperOperation.m:320 Examining keyPath '<null>' for mappable content...
D restkit.object_mapping:RKMapperOperation.m:297 Found mappable collection at keyPath '<null>': (
"https://server1.com",
"https://server2.com"
)
*** Assertion failure in NSDictionary *RKEntityIdentificationAttributesForEntityMappingWithRepresentation(RKEntityMapping *__strong, NSDictionary *__strong)(), /Users/jonukas/MyApp/Pods/RestKit/Code/CoreData/RKManagedObjectMappingOperationDataSource.m:83
…
我猜 (null) targetObject 可能是我的问题。
更新 2:RestKit 0.21.0 修复了该问题。
【问题讨论】: