RestKit multiple RKObjectManagers object mapping

2019-08-08 13:18发布

问题:

I'm using two RKObjectManagers, one without an RKManagedObjectStore, (which is the shared instance) and one with. When I attempt to set the RKManagedObjectStore like so:

[self.storeBackedObjectManager setObjectStore:[RKManagedObjectStore objectStoreWithStoreFilename:@"conversations.sqlite"]];

I get the following error:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '[RKObjectManager sharedManager].objectStore cannot be nil'

It seems that RestKit is trying to access the objectstore of the sharedManager (which doesn't use an object store), in NSManagedObject+ActiveRecord.m:

+ (NSManagedObjectContext*)managedObjectContext {
NSAssert([RKObjectManager sharedManager], @"[RKObjectManager sharedManager] cannot be nil");
NSAssert([RKObjectManager sharedManager].objectStore, @"[RKObjectManager sharedManager].objectStore cannot be nil");
return [[[RKObjectManager sharedManager] objectStore] managedObjectContext];

}

Is there any way to pass a reference to my second, store backed RKObjectManager instance? (This mapping works fine if I temporarily set the shared manager to the store backed instance)

回答1:

You are trying to use a shared RKObjectManager for managed (coredata) and unmanaged models. You have to set objectStore property for that RKObjectManager.

I think you can use two RKObjectManagers separately, just create them using initWithBaseURL