Search code examples
iosswiftcore-datamappingrestkit

Mixing NSManagedObjects and regular Objects in RestKit


Our backend API returns an object that I don't want to store in my local CoreData instance. This object contains nested objects, however, which I do want to store in the database.

I implemented this using two mappings:

  1. A RKObjectMapping that maps my regular, non-NSManagedObject A.
  2. A RKEntityMapping mapping for my NSManagedObject B.

Then I connected both by adding the following to A's mapping:

mappingA.addPropertyMapping(
    RKRelationshipMapping(fromKeyPath: "b",
        toKeyPath: "b",
        withMapping: B.mapping()
    )
)

As it seemed to work fine, I never questioned this approach. But now I'm not so sure if this configuration is actually supported by RestKit.

So, can you mix RKEntityMappings and RKObjectMappings in RestKit like above?


Solution

  • Yes, you can, a good number of people have been doing it for quite a long time. But, in general the code for the two is organised separately, so it's the kind of thing which will have less effective testing and so may be more error prone. Any issues will be noticed and raised to the development team quite quickly, but it may mean you need to avoid some versions / commits.