【问题标题】:RestKit delete semanticsRestKit 删除语义
【发布时间】:2012-10-01 00:52:42
【问题描述】:

RestKit 与 Core Data 一起使用时的删除语义是什么?

例如,假设我在 RestKit 中为组织实体正确设置了 primaryKeyAttribute。如果我在 /organizations/ 上执行 GET,我会返回 /organizations/1//organizations/2//organizations/3/ 的条目。假设我稍后在 /organizations/ 上执行 GET,并且只获取 /organizations/1//organizations/3/ 的条目。 `/organizations/2/ 已在服务器上删除。

我希望 RestKit 删除我的 /organizations/2/ 的核心数据记录。这是 RestKit 所做的还是我必须实现此行为?如果我使用的是 reboot-networking-layer 分支,这是否会发生任何变化? RestKit 中是否有任何我应该注意的设置会影响此行为?

【问题讨论】:

    标签: core-data restkit


    【解决方案1】:

    您需要实现 FetchRequests 才能删除这些对象。这是一个简单的例子:

        [objectManager addFetchRequestBlock:^NSFetchRequest *(NSURL *URL) {
        RKPathMatcher *pathMatcher = [RKPathMatcher pathMatcherWithPattern:@"/organizations"];
    
        NSDictionary *argsDict = nil;
        BOOL match = [pathMatcher matchesPath:[URL relativePath] tokenizeQueryStrings:NO parsedArguments:&argsDict];
    
        if (match) {
            NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:@"Organization"];
            return fetchRequest;
        }
    
        return nil;
    }];
    

    我在 ApplicationDelegate 中执行此操作(与我设置 RestKit 的位置相同)。在那里执行此操作后,所有其他调用将自动删除孤立对象。

    【讨论】:

      猜你喜欢
      • 2017-06-04
      • 1970-01-01
      • 2023-04-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-12
      • 1970-01-01
      • 2012-07-16
      相关资源
      最近更新 更多