问题
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?
回答1:
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.
来源:https://stackoverflow.com/questions/18232620/restkit-0-20-how-to-post-get-more-than-1-managed-object-without-a-wrapper-class