我从a changes for Restkit that was commited about 6 months ago看到 - Restkit支持使用外键数组映射JSON结构:
supports structure such as:
{
items: [{id: 1}, {id: 2}, {id: 3}],
itemgroups: [{items: [1, 2]}, {items:[2, 3]}]
}
我的问题是,有人能告诉我如何将此功能用于核心数据吗?
我确实检查了Restkit源代码并找到了the following code demonstrated the usage of changes。但它们似乎不适用于CoreData。
RKManagedObjectMapping *humanMapping = [RKManagedObjectMapping mappingForClass:[RKHuman class] inManagedObjectStore:objectStore];
humanMapping.primaryKeyAttribute = @"railsID";
[humanMapping mapAttributes:@"name", @"favoriteCatID", @"catIDs", nil];
[humanMapping mapRelationship:@"cats" withMapping:catMapping];
[humanMapping connectRelationship:@"cats" withObjectForPrimaryKeyAttribute:@"catIDs"];
人类对象中的catIDs属性是NSArray:
@interface RKHuman : NSManagedObject {
}
@property (nonatomic, retain) NSNumber *railsID;
@property (nonatomic, retain) NSString *name;
@property (nonatomic, retain) NSSet *cats;
@property (nonatomic, retain) NSArray *catIDs;
测试用例是通过NSArray实现的。但我们都知道Coredata无法生成 NSArray类型属性。所以这个演示代码在现实世界中没有意义,这仅仅是为了测试目的。有谁知道我应该如何使用这个功能:通过主键实现多对多关系?