RestKit + MagicalRecord + Swift
RestKit is compatible with MagicalRecord, however it requires some kind of hack to get it working:
See: RKMagicalRecord / RKMRAppDelegate.m @ L15-L18
// Use a class extension to expose access to MagicalRecord private setter methods @interface NSManagedObjectContext () + (void)MR_setRootSavingContext:(NSManagedObjectContext *)context; + (void)MR_setDefaultContext:(NSManagedObjectContext *)moc; @end
Thus, they use a somewhat hacky approach to access the private method MR_setRootSavingContext
.
I know that in swift I can define extensions, but then I have to implement them, how can I achieve the same workaround in swift.
Or more generally how to configure Magical Record to use the NSManagedObjectContext
one created by RestKit.
Just (not good, maybe) it creates a bridge file
and add there
@interface NSManagedObjectContext ()
+ (void)MR_setRootSavingContext:(NSManagedObjectContext *)context;
+ (void)MR_setDefaultContext:(NSManagedObjectContext *)moc;
@end
Here's an example of creating a bridging file http://ios-blog.co.uk/tutorials/how-to-create-an-objective-c-bridging-header/
what you need to do specify a header file named NSMangedObjectContext_MagicalRecordify
with content:
@interface NSManagedObjectContext ()
+ (void)MR_setRootSavingContext:(NSManagedObjectContext *)context;
+ (void)MR_setDefaultContext:(NSManagedObjectContext *)moc;
@end
then in your bridge header compiler, import:
#import "NSMangedObjectContext_MagicalRecordify.h"
then you can access those private methods in your swift file.