无法使RKPathMatcher pathMatcher与删除孤立对象相匹配

时间:2015-02-21 18:28:03

标签: ios objective-c core-data restkit

我在删除路径匹配器永远不会匹配的孤立对象时遇到问题。如果路径在路径中包含2个ID,我应该使用什么作为路径。感谢。

即/ api / getEntity / 1234/123其中1234是父ID,123是实体ID

请求块如下:

  NSMutableURLRequest *request = [NSMutableURLRequest
 requestWithURL:[NSURL URLWithString:formattedUrl]];
     [sharedManager addFetchRequestBlock:^NSFetchRequest *(NSURL *URL) {

        RKPathMatcher *pathMatcher = [RKPathMatcher pathMatcherWithPattern::@"/api/getEntity/all/:parentEntityId/:entityId/"];         NSDictionary *argsDict = nil;
        BOOL match = [pathMatcher matchesPath:[URL relativePath] tokenizeQueryStrings:NO parsedArguments:&argsDict];
        if(match){
            NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
            NSEntityDescription *entity = [NSEntityDescription entityForName:@"SomeEntity" inManagedObjectContext:[RKManagedObjectStore
 defaultStore].mainQueueManagedObjectContext];
             [fetchRequest setEntity:entity];             return fetchRequest;
        }
        return nil;
    }];

1 个答案:

答案 0 :(得分:1)

这看起来就像您要加载的网址路径不匹配以及/api/getEntity/all/:parentEntityId/:entityId/的匹配器规范,因为您通常不会在网址上添加一个斜杠,因为它表示一个目录而您和#39;实际上正在加载一个'页面'。斜线和因此结构对匹配器很重要。

所以,删除尾部斜杠。

一般来说,您的基本网址应该有一个尾部斜杠,并且您的所有路径模式都不应该包含前导或斜杠。

相关问题