magicalpanda / MagicalRecord

Super Awesome Easy Fetching for Core Data!
Other
10.8k stars 1.79k forks source link

Couple of updates for concurrency debug branch #1164

Closed pronebird closed 6 years ago

pronebird commented 8 years ago

Besides I think persistent store initialization should be entirely moved out from accessors for -context, -coordinator and such. I have some funky side effects when a call to -coordinator rolls out infinite loop initialization and crash because ivars are not set and this happens in response to notification sent at the point when new store is added.

-loadStack is really a good place to do all that work at once. This is particularly important for iCloud stack which posts important notifications right away.

That's why I had to implement my own createCoordinatorWithOptions in iCloud stack:

- (NSPersistentStoreCoordinator *)createCoordinatorWithOptions:(NSDictionary *)options
{
    MRLogVerbose(@"Loading Store at URL: %@", self.storeURL);
    NSPersistentStoreCoordinator *coordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self model]];

    // register for storesWillChange, storesDidChange, etc..
    // otherwise we'll miss them...
    [self registerForiCloudNotifications:coordinator];

    NSMutableDictionary *storeOptions = [options mutableCopy];
    [storeOptions addEntriesFromDictionary:self.storeOptions];

    NSPersistentStore *store = [coordinator MR_addSqliteStoreAtURL:self.storeURL withOptions:storeOptions];

   // ...
}
pronebird commented 6 years ago

Closing due to absence of interest in proceeding with this PR.