【发布时间】:2013-06-14 14:07:56
【问题描述】:
我正在使用 RestKit RKObjectManager 从我的服务器获取数据并存储在核心数据中(请参阅我的另一个 post)
我想配置数据库中遗留的旧条目的删除行为。
我看到 RKEntityMapping 类中有一个 deletePredicate 属性,但我知道它仅在服务实际返回标记为“待删除”的要删除的对象时使用。 (我说的对吗?)
在我的情况下,当某些对象必须被删除时,它们只是不被服务器返回,我想让我的客户端应用明白这意味着它应该删除它们。
这可能吗?如果有,怎么做?
编辑:
好的,我查看了that link,并将这个获取请求块添加到我的 RKObjectManager 中:
[[RKObjectManager sharedManager] addFetchRequestBlock:^NSFetchRequest *(NSURL *URL) {
RKPathMatcher *pathMatcher = [RKPathMatcher pathMatcherWithPattern:@"/path_to_ressource"];
NSDictionary *argsDict = nil;
BOOL match = [pathMatcher matchesPath:[URL relativePath] tokenizeQueryStrings:NO parsedArguments:&argsDict];
if (match) {
NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:@"Entity"];
fetchRequest.sortDescriptors = @[ [NSSortDescriptor sortDescriptorWithKey:@"entityId" ascending:YES] ];
return fetchRequest;
}
return nil;
}];
我保留了 sortDescriptor,但它的目的到底是什么?
【问题讨论】:
标签: ios restkit nsmanagedobject