使用postObject

时间:2013-01-31 04:03:50

标签: ios restkit

我是使用RESTKit的新手。

我正在尝试使用postObject进行简单的POST。

我想知道我是否正确地这样做了。

我有这段代码:

self.gameWebInteractionObject = [[GameWebInteraction alloc] init];
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[NSMutableDictionary class]];
[mapping mapAttributes:@"id", @"firstname", @"lastname", @"email", @"createdGames", nil];
[self.gameWebInteractionObject.manager.mappingProvider setMapping:mapping forKeyPath:@""];


self.gameWebInteractionObject.manager.serializationMIMEType = RKMIMETypeJSON;
[self.gameWebInteractionObject.manager.router routeClass:[UserObject class] toResourcePath:@"/data" forMethod:RKRequestMethodPOST];
[self.gameWebInteractionObject.manager.mappingProvider setSerializationMapping:[mapping inverseMapping] forClass:[UserObject class]];
[self.gameWebInteractionObject.manager postObject:userobject delegate:self];

1 个答案:

答案 0 :(得分:2)

如果您使用RestKit 0.20

// POST to create
[manager postObject:article path:@"/data" parameters:nil success:nil failure:nil];

// PATCH to update
[manager patchObject:article path:@"/data/1" parameters:nil success:nil failure:nil];

// DELETE to destroy
[manager deleteObject:article path:@"/data/1" parameters:nil success:nil failure:nil];

1是我的身份证。

https://github.com/RestKit/RestKit