Michał Banasiak
Michał Banasiak

Reputation: 960

RestKit: One to many relationship mapping

I'm trying to parse github's gist api response with RestKit. Here is a fragment of json:

  {
    "url": "https://api.github.com/gists/6004248",
      ...
    "html_url": "https://gist.github.com/6004248",
    "files": {
      "ApplicationContext.h": {
        "filename": "ApplicationContext.h",
        "type": "text/plain",
        "language": "Objective-C",
        "raw_url": "https://gist.github.com/raw/6004248/4531c7534585b273c55ca71ce9020418b7ed271b/ApplicationContext.h",
        "size": 481
      },
      "ApplicationContext.m": {
        "filename": "ApplicationContext.m",
        "type": "text/plain",
        "language": "Objective-C",
        "raw_url": "https://gist.github.com/raw/6004248/27a3881f9c5adde700b75199076a5ce259d0b568/ApplicationContext.m",
        "size": 542
      }
    },
      ...
    "user": {
      ...
    },
    "comments_url": "https://api.github.com/gists/6004248/comments"
  },

Everything works fine, but i have problem with a files relationship. Here is a fragment of code responsible for files:

RKObjectMapping *gistMapping = [RKObjectMapping mappingForClass:[MBGist class]];
[gistMapping addAttributeMappingsFromDictionary: @{@"url": @"url", @"html_url": @"htmlUrl", @"description": @"description"}];

RKObjectMapping *fileMapping = [RKObjectMapping mappingForClass:[MBFile class]];
[fileMapping addAttributeMappingsFromDictionary:@{@"filename": @"filename", @"language": @"language", @"type":@"type"}];

[gistMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"files" toKeyPath:@"files" withMapping:fileMapping]];

but I have empty files arrays in my MBGist class objects.

Can anybody help me with it?

Best Regards, Michał

Upvotes: 0

Views: 1131

Answers (1)

Kyle Fang
Kyle Fang

Reputation: 1199

Please refer to Handling Dynamic Nesting Attributes section in Restkit ObjectMapping

Upvotes: 2

Related Questions