ALM is great. But I can't get it to work on a project that uses Core Data with NSDocument. It seems that ALM is disabled by default.
Fine. For any normal project, you'd add the two appropriate options to the dictionary in this line:
if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:options error:&error])
...but that line doesn't exist when using CD with NSD (NSPersistentDocument hides the details and I can't see how you can modify them).
The following method seems to offer hope:
configurePersistentStoreCoordinatorForURL:ofType:modelConfiguration:storeOptions:error:
...some people on mailing lists (from 4+ years ago) report success overriding that method, altering the options dictionary, and then re-invoking it on "super". That didn't work for me, sadly. I would advise trying that first if you have similar problems - then come back here if it still doesn't work :)
Making a new Cored-Data-with-NSDocument project from scratch, I tried the approach that didn't work originally, and it worked fine this time:
-(BOOL)configurePersistentStoreCoordinatorForURL:(NSURL *)url ofType:(NSString *)fileType modelConfiguration:(NSString *)configuration storeOptions:(NSDictionary *)storeOptions error:(NSError **)error
{
NSMutableDictionary *newOptions = [NSMutableDictionary dictionaryWithDictionary:storeOptions];
[newOptions setValue:@"YES" forKey:NSMigratePersistentStoresAutomaticallyOption];
[newOptions setValue:@"TRUE" forKey:NSInferMappingModelAutomaticallyOption];
return [super configurePersistentStoreCoordinatorForURL:url ofType:fileType modelConfiguration:configuration storeOptions:newOptions error:error];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With