我已经定义了一个相当简单的映射,有一些普通的属性,但是现在我遇到了一个问题,我在服务器上的数据结构是一个树,所以我得到了一个包含一些属性的"CustomObject“列表和一个"CustomObject”列表。
因此,在代码中,它看起来像这样(简化)
+ (RKObjectMapping*)getCustomObjectMapping
{
RKObjectMapping* customObjectMapping = [RKObjectMapping mappingForClass:[CustomObject class]];
[customObjectMapping mapKeyPath:@"title" toAttribute:@"title"];
[..]
// Define the relationship mapping
//[customObjectMapping mapKeyPath:@"nextLevel" toRelationship:@"nexLevel" withMapping:[self getCustomObjectMapping]];
return customObjectMapping;
}
这显然会导致无休止的递归。
有没有一种聪明的方法来做这种映射呢?
发布于 2013-04-12 21:03:15
它非常简单,最近的RestKit库也很好地支持它。您需要引用正在构造的映射对象,而不是递归引用+getCustomObjectMapping。下面是你需要做的事情:
+ (RKObjectMapping*)getCustomObjectMapping
{
RKObjectMapping* customObjectMapping = [RKObjectMapping mappingForClass:[CustomObject class]];
[customObjectMapping mapKeyPath:@"title" toAttribute:@"title"];
[..]
// Define the relationship mapping
[customObjectMapping mapKeyPath:@"nextLevel" toRelationship:@"nexLevel" withMapping:customObjectMapping];
return customObjectMapping;
}
https://stackoverflow.com/questions/11761718
复制相似问题