我有2个json文件,Checkpoint
{
"city_id": 1,
"code_number": "01248",
"description": "\"км 6+300 а/д до с/т \"\"Лаванда\"\" от а/д \"\"Обход г. Тюмени\"\" (поворот на км 3 + 750)\"",
"hash": "c542a380e87ee3ddae153b22d504002e",
"id": 771,
"lat": 57.24386170206,
"lon": 65.485205100524,
"name": "\"с/о Текстильщик, (с/о Текстильщик 2, бывш. конечная) (в город, м-т №36)\"",
"routes_ids": [
368,
372,
397,
398,
399,
400,
873
]
},
和路线
{
"active_from": "2014-03-25",
"active_to": "2024-01-01",
"capacity_type": "",
"checkpoints_ids": [
319,
321,
338,
....
3375
],
"city_id": 1,
"description": "Областная библиотека - с/о Липовый остров",
"has_cars_for_disabled_persons": false,
"hash": "49587333a979a22d93d09e4313661eaa",
"id": 125,
"name": "156",
"route_type_id": 3
}
我正在使用easymapping将json映射到核心数据。这2个json文件在selfs之间有关系,在Checkpoint中有一个关键的routes_ids,它引用Route.id,而Route有关键的checkpoints_ids,它引用了Checkpoint.id。 这是我的映射: 路线映射
+ (EKManagedObjectMapping *)objectMapping{
return [EKManagedObjectMapping mappingForEntityName:NSStringFromClass([self class]) withBlock:^(EKManagedObjectMapping *mapping){
[mapping mapPropertiesFromArray:@[@"name"]];
[mapping mapPropertiesFromDictionary:@{@"capacity_type":@"capacityType",
@"id":@"identifier",
@"description":@"sequenceDescription",
@"hash":@"objectHash"}];
[mapping hasMany:[Checkpoint class] forKeyPath:@"checkpoints_ids" forProperty:@"identifier"];
}];
}
和检查点映射:
+ (EKManagedObjectMapping *)objectMapping{
return [EKManagedObjectMapping mappingForEntityName:NSStringFromClass([self class]) withBlock:^(EKManagedObjectMapping *mapping){
[mapping mapPropertiesFromArray:@[@"name"]];
[mapping mapPropertiesFromDictionary:@{@"description":@"checkpointDescription",
@"id":@"identifier",
@"code_number":@"codeNumber",
@"lat":@"latitude",
@"lon":@"longtitude",
@"hash":@"objectHash"}];
[mapping hasMany:[Route class] forKeyPath:@"routes_ids" forProperty:@"identifier"];
}];
}
这是日志:
2015-11-26 10:37:13.989 TTCore Light[5458:2197534] *** Assertion failure in -[EKManagedObjectMapping hasMany:forKeyPath:forProperty:withObjectMapping☺, /Users/tgt0/Desktop/test/TTCore Light/Pods/EasyMapping/EasyMapping/EKObjectMapping.m:245
2015-11-26 10:37:13.992 TTCore Light[5458:2197534] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: [objectClass conformsToProtocol:@protocol(EKMappingProtocol)] || [objectClass conformsToProtocol:@protocol(EKManagedMappingProtocol)]'
*** First throw call stack:
(0x2476985b 0x35e2adff 0x24769731 0x254faddb 0x94d23 0x94b53 0x86cf9 0x8e989 0x86aab 0x88f0d 0x244e434b 0x1e161b 0x1d9f53 0x1e2b0f 0x1e2961 0x366e4e0d 0x366e49fc)
libc++abi.dylib: terminating with uncaught exception of type NSException
我很有兴趣如何处理我的数组以建立正确的关系 我找不到关于这个框架的完整文档。或者也许有人可以向我推荐另一种具有最佳结果的解决方案(完整文档,性能等)