2
votes

I need to split my Core Data persistent storage (managed by RestKit) into two parts. One part should persist only in memory and not be saved to disk, and the other part should be saved. Usually it is done by adding configurations to Core Data object model and creating two stores for each configuration. But RestKit's RKManagedObjectStore method - (NSPersistentStore )addInMemoryPersistentStore:(NSError *)error; doesn't take configuration name and adds persistent store with configuration nil:

- (NSPersistentStore *)addInMemoryPersistentStore:(NSError **)error
{
    if (! self.persistentStoreCoordinator) [self createPersistentStoreCoordinator];

    return [self.persistentStoreCoordinator addPersistentStoreWithType:NSInMemoryStoreType configuration:nil URL:nil options:nil error:error];
}

According to Core Data documentation, this prevents from using any configurations in persistent store coordinator. I can reload this method and make it use configuration, but first I want to ask: Are there any reasons for me to not to do this? There must be reasons why addInMemoryPersistentStore looks like it looks. May be someone had tried to make the same thing as I'm going to do and found that it doesn't work?

1

1 Answers

2
votes

I would say that you should create your own version of the method which takes a configuration parameter. I don't think that you're missing anything, I just think that if RestKit was to offer support for 100% of the Core Data configuration API out of the box then there would be a lot of code to maintain and very few people would benefit from all of the extra effort.

Your best option is to subclass and add the method you want, calling super as appropriate, and then instantiate that subclass and pass it when you are configuring your Core Data stack (managed object store).