Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The restkit does not fund routable path for NSArray, because you defined your routing for <code>NSManagedObject</code> class. You probably want to create a custom class, say <code>MySyncEntity</code> that holds the ivars you define in your mapping. Then, you create your mapping like this:</p> <pre><code>RKObjectMapping* mapping = [RKObjectMapping mappingForClass:[MySyncEntity class]]; .... [myManager setSerializationMIMEType:RKMIMETypeJSON]; [[myManager router] routeClass:[MySyncEntity class] toResourcePath:@"/sync"]; </code></pre> <p>then you should be able to post your object to the API backend as JSON object.</p> <p><strong>Further clarification:</strong></p> <p>In this case, we want to post an array of <code>NSManagedObject</code> instances into a JSON based API. To do that we need to create a sync entity, that holds the objects in an array:</p> <pre><code>@interface MySyncEntity : NSObject {} @property (nonatomic, retain) NSArray* mySyncArray; ... @end </code></pre> <p>The <code>mySyncArray</code> will hold the payload we'd like to submit to the rest backend. Then, we create appropriate mapping for both <code>NSManagedObject</code> that will be sent in <code>mySyncArray</code> and the <code>MySyncEntity</code> entity itself.</p> <pre><code>RKObjectManager *manager = [RKObjectManager objectManagerWithBaseURL:kBaseUrl]; ... RKObjectMapping *mngObjMapping = [RKObjectMapping mappingForClass:[NSManagedObject class]]; [mngObjMapping mapKeyPath: @"time" toAttribute:@"time"]; [mngObjMapping mapKeyPath: @"recordLevel" toAttribute:@"recordLevel"]; .... //map as many properties as you wish [[manager mappingProvider] setSerializationMapping:[mngObjMapping inverseMapping] forClass:[NSManagedObject class]]; //now, we create mapping for the MySyncEntity RKObjectMapping *syncEntityMapping = [RKObjectMapping mappingForClass:[MySyncEntity class]]; [syncEntityMapping mapKeyPath:@"mySyncArray" toRelationship:@"mySyncArray" withMapping:mngObjMapping]; [[manager mappingProvider] setSerializationMapping:[syncEntityMapping inverseMapping] forClass:[MySyncEntity class]]; </code></pre> <p>Now with the mappings defined we can post the object to the server </p> <pre><code>[manager postObject:mySyncInstance delegate:nil]; </code></pre> <p>The contents of <code>mySyncInstance</code> array will be mapped according to <code>mngObjMapping</code> and sent to defined rest endpoint.</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