ray
ray

Reputation: 2045

RestKit 0.20: How to POST/GET more than 1 managed object without a wrapper class?

Currently I have several instances where I need to send a group of objects to the server:

{
    "things": [
        {
            //object stuff
        },
        {
            //object stuff
        },
        ...
    ]
}

So what I've been doing is defining an intermediate object MyThingPayload

@interface MyThingPayload
@property (nonatomic, strong) NSArray *things;
@end

And then when mapping

RKObjectMapping *mapping = [RKObjectMapping mappingForClass:NSClassFromString(@"MyThingPayload")];

[mapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"things"
                                                                        toKeyPath:@"things"
                                                                      withMapping:[self entityMappingForManagedThingObject]]];

Seems like unnecessary overhead. Is there a way to do this without the intermediate object that holds an array?

Upvotes: 0

Views: 101

Answers (1)

Wain
Wain

Reputation: 119031

You need an intermediate object to provide the structure to be used during serialisation. It doesn't need to be a custom class though, it can just be an NSDictionary containing the correct key and NSArray value.

Upvotes: 1

Related Questions