RestKit 0.20 — What is the preferred way to create a new NSManagedObject?

前端 未结 2 1982
青春惊慌失措
青春惊慌失措 2021-02-06 07:03

I\'m curious to know what the best way is to create a new NSManagedObject in RestKit 0.20? Currently my code looks something like this:

#pragma mark - navigation         


        
2条回答
  •  面向向阳花
    2021-02-06 07:40

    The way you do it should works (calling each time the MOC in each of your VC), but is not "recommended".

    What Apple suggests, just like any Core Data app, is the "pass the baton" style.

    Nested contexts make it more important than ever that you adopt the “pass the baton” approach of accessing a context (by passing a context from one view controller to the next) rather than retrieving it directly from the application delegate.

    See here: http://developer.apple.com/library/ios/#releasenotes/DataManagement/RN-CoreData/_index.html

    As for your second question, RestKit should manage saving/updating your Core Data stack upon success of your api calls if everything is well mapped/setup.

    From blake the RK creator:

    if you POST or PUT a Core Data object, RK obtains a permanent object ID for it and then creates a secondary managed object context, fires the request, and maps the response (if possible). if the response and the mapping are successful, it will either save it back to the parent context or all the way back to the persistent store (i.e. into SQLite) based on the value of the savesToPersistentStore.

提交回复
热议问题