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

喜欢而已 提交于 2019-12-12 04:38:44

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!