Reputation: 9835
My application sends a POST request to a server with some parameters, and the server responds with an array of objects. I've been using RKObjectManager's managedObjectRequestOperationWithRequest:managedObjectContext:success:failure: function to do this, but after having some issues with a mysterious intermittent crash that I suspect is related to the underlying restkit code (RestKit Core Data NSError dealloc Crash) I recently did another read through of the docs and came across RKObjectManager's postObject:path:parameters:success:failure function.
Substituting this in place of the managedObjectRequestOperation does not seem to have any negative effects, and everything is operating as expected and thus my main question is are these two functions different in any significant way where given my described use-case I should prefer one to the other?
A secondary question to this is I'm using CocoaLumberjack to handle debug logging to the console/file, and I'd like the raw JSON (prior to being mapped to objects) to be logged for debugging. The only solution I've found to do this is to do something like this:
[operation setWillMapDeserializedResponseBlock:^id(id deserializedResponseBody) {
DDLogInfo(@"%@", deserializedResponseBody);
return deserializedResponseBody;
}];
This worked before when I was doing a managedObjectRequestOperation, as doing so involved creating an instance of it before configuring it further and telling it to start, but using something the object manager's postObject function as described doesn't involve creating/returning an instance of the operation that I can set the willMapDeserializedResponseBlock on... Any ideas?
Upvotes: 0
Views: 135
Reputation: 119031
You should prefer postObject:path:parameters:success:failure
because it's the higher level API. The difference is that the operation gives you more access to the underlying system and request, but if you don't need that you should let the manager handle it for you.
For debug purposes you can use
RKLogConfigureByName("RestKit/ObjectMapping", RKLogLevelTrace);
or a lower level.
Upvotes: 1