Where's the best place to put object mappings in RestKit

前端 未结 3 1289
栀梦
栀梦 2021-02-04 16:12

I\'m using RestKit for a project and i noticed that there is no longer a method in the class that you can control all mappings in (elementToPropertyMappings), i therefore wonder

3条回答
  •  隐瞒了意图╮
    2021-02-04 16:32

    There are a few good ways to organize your mappings currently recommended:

    1. Put all of your mappings into your app delegate and configure them at app initialization. This keeps them out of the controllers and is useful if you have a small number of mappings.
    2. Subclass the RKObjectMappingProvider and build all of your mappings in the init method of your subclass, then instantiate and assign your mapping provider instance to the object manager.
    3. Add a category to RKObjectMappingProvider with a method like 'defineMappings'. Then import the header into your app delegate and invoke it via [mappingProvider defineMappings] after you initialize RestKit.

    The problem with defining mappings on a class method is that when you have relationships, you can wind up with circular dependencies as there's no ivars available to store the instances. We may be able to do something with blocks to help alleviate this problem, but no such work has been done yet.

提交回复
热议问题