Ios RestKit递归映射

Ios RestKit递归映射,ios,restkit,Ios,Restkit,我已经定义了一个非常简单的映射,有一些简单的属性,但是现在我遇到了一个问题,服务器上的数据结构是一个树,所以我得到了一个“CustomObject”列表,其中包含一些属性和一个“CustomObject”列表,其中 所以在代码中看起来是这样的(简化) 这显然会导致无休止的递归 有没有一种聪明的方法可以实现这种映射?它非常简单,最近的RestKit库对它的支持非常好。 您需要引用正在构造的映射对象,而不是递归地引用+getCustomObjectMapping。 以下是您需要如何做到这一点: +

我已经定义了一个非常简单的映射,有一些简单的属性,但是现在我遇到了一个问题,服务器上的数据结构是一个树,所以我得到了一个“CustomObject”列表,其中包含一些属性和一个“CustomObject”列表,其中

所以在代码中看起来是这样的(简化)

这显然会导致无休止的递归


有没有一种聪明的方法可以实现这种映射?

它非常简单,最近的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;
}

您是否可以控制web服务器响应结构?这通常不是传递图形结构的方式。你可能想看看Facebook Graph API是如何实现的(即:分别检索节点和连接)。你的意思是检索第一个级别,可能还有一个标志或显示是否有子级别的东西?这是另一种方式。递归web服务调用是完全不可伸缩的,也不是RESTful的。再来看看Facebook。
+ (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;
}