Best Approach for Creating a Temp Object for Master Data Using Restkit

In my application, I have such a scenario where I need to place an object on a remote server and get the object key back, and then save the object locally. I have Core and Restkit data implemented in my application.

The value of the object is collected from user input. I could not find a great way to prepare the object before sending it to the remote server. This object is an object of type NSManagedObject, and I do not want to store it until I get the object identifier from the server.

I came across this , which suggested using a transition object to handle this situation. But, as discussed in this thread, this causes problems with code maintenance.

Is there a better way to handle this scenario? Thanks.

+1
source share
1 answer

Make your main data model class tied to the RKRequestSerializable protocol.

Then, when user input is validated, create the object as normal and set it as the params value in RKRequest, this will send your object as an HTTP body. For example, look at RKParams.m.

Also set the newly created object as the targetObject for RKObjectLoader. Thus, when your web service returns information (for example, a new unique identifier), it will be aimed at a new object and save a new unique identifier for this object without creating a duplicate.

Remove like dirt?

PS: Oh, be careful when mixing data classes with auto-generated kernels with custom code! I recommend mogen so as not to lose code with every change.

+3
source

Source: https://habr.com/ru/post/911795/


All Articles