RestKit simple JSON, bad pathPAttern?

JSONs:

Code:

NSURL *baseURL = [NSURL URLWithString:@"http://www.krzysztofkurzawa.com"];
RKObjectManager *objectManager = [RKObjectManager managerWithBaseURL:baseURL];

RKLogConfigureByName("RestKit/Network", RKLogLevelTrace);
RKLogConfigureByName("RestKit/ObjectMapping", RKLogLevelTrace);

RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[NSMutableDictionary class]];
[mapping addAttributeMappingsFromArray:@[@"title"]];

RKResponseDescriptor *rk = [RKResponseDescriptor responseDescriptorWithMapping:mapping pathPattern:@"articles" keyPath:@"articles" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
[objectManager addResponseDescriptor:rk];

RKObjectMapping *mapping2 = [RKObjectMapping mappingForClass:[NSMutableDictionary class]];
[mapping addAttributeMappingsFromArray:@[@"title"]];

RKResponseDescriptor *rk2 = [RKResponseDescriptor responseDescriptorWithMapping:mapping2 pathPattern:@"articles/:id" keyPath:nil statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
[objectManager addResponseDescriptor:rk2];


[[RKObjectManager sharedManager] getObjectsAtPath:@"articles" parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
    NSLog(@"%@", [mappingResult firstObject]);
} failure:^(RKObjectRequestOperation *operation, NSError *error) {

}];

[[RKObjectManager sharedManager] getObjectsAtPath:@"articles/1" parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
    NSLog(@"%@", [mappingResult firstObject]);
} failure:^(RKObjectRequestOperation *operation, NSError *error) {

}];

Error:
No mappable object representations were found at the key paths searched.”, keyPath=null, NSLocalizedDescription=No response descriptors match the response loaded.}

I haven’t got any ideas…first mapping works when pathPattern is set to “nil”…why it should be nil? I think it’s needed to creating rest path patterns???


Source: ios

Leave a Reply