Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to add mapping between not embedded JSON objects and relationships using RestKit 0.2 and Core Data?
    text
    copied!<p>I'm developing my first iOS application that uses RestKit 0.2 and Core Data. Most of the time I have followed this great tutorial <a href="http://www.alexedge.co.uk/blog/2013/03/08/introduction-restkit-0-20/" rel="nofollow noreferrer">http://www.alexedge.co.uk/blog/2013/03/08/introduction-restkit-0-20/</a> however it doesn't fit my requirements since it describes embedded JSON objects and I need to create separate objects. Here is a simplified scenario of my app structure:</p> <p><strong>JSON response:</strong></p> <pre><code>"application": [ { "appId": "148", "appName": … . . . (more attributes) } ], "image": [ { "imgId": "308", "appId": "148", "iType": "screenshot", "iPath": .. . . . }, { "imgId": "307", "appId": "148", "iType": "logo", "iPath": … . . . } ] </code></pre> <p>I have created a data model that contains two entities and set the relationship between them in a way that one application may have more than one image and one image may only belong to one application:</p> <p><img src="https://i.stack.imgur.com/hO1ab.png" alt="enter image description here"></p> <p>I have used mogenerator to create classes represented by entities.</p> <p>I can successfully map the entity to Application object using the following code:</p> <pre><code>NSDictionary *parentObjectMapping = @{ @"appId" : @"appId" }; // Map the Application object RKEntityMapping *applicationMapping = [RKEntityMapping mappingForEntityForName:NSStringFromClass([Application class]) inManagedObjectStore:managedObjectStore]; applicationMapping.identificationAttributes = @[ @"appId" ]; [applicationMapping addAttributeMappingsFromDictionary:@{ @"appName" : @"name", @"appCat" : @"category", @"appType" : @"type", @"compName" : @"companyName", @"compWeb" : @"companyWebsite", @"dLink" : @"downloadWebLink", @"packageName" : @"appStoreLink", @"osMinVer" : @"minRequirements", @"appCost" : @"cost", @"appDescription" : @"appDescription" }]; [applicationMapping addAttributeMappingsFromDictionary:parentObjectMapping]; // Register our mappings with the provider [manager addResponseDescriptorsFromArray:@[ [RKResponseDescriptor responseDescriptorWithMapping:applicationMapping pathPattern:nil keyPath:@"application" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)] ]]; </code></pre> <p>Now I have a problem when mapping the JSON to the image object with the appropriate relationship between Image and Application. How can I add the mapping between the two Entities? Is my data model correct or I'm missing something?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload