diff --git a/Code/CoreData/RKManagedObjectStore.m b/Code/CoreData/RKManagedObjectStore.m index aa0f1087..f3167114 100644 --- a/Code/CoreData/RKManagedObjectStore.m +++ b/Code/CoreData/RKManagedObjectStore.m @@ -54,7 +54,11 @@ static RKManagedObjectStore *defaultStore = nil; + (void)setDefaultStore:(RKManagedObjectStore *)managedObjectStore { - @synchronized(defaultStore) { + if (defaultStore) { + @synchronized(defaultStore) { + defaultStore = managedObjectStore; + } + } else { defaultStore = managedObjectStore; } } @@ -320,7 +324,7 @@ static RKManagedObjectStore *defaultStore = nil; // We can only do migrations within a versioned momd if (![[momdURL pathExtension] isEqualToString:@"momd"]) { NSString *errorDescription = [NSString stringWithFormat:@"Migration failed: Migrations can only be performed to versioned destination models contained in a .momd package. Incompatible destination model given at path '%@'", [momdURL path]]; - *error = [NSError errorWithDomain:RKErrorDomain code:NSMigrationError userInfo:@{ NSLocalizedDescriptionKey: errorDescription }]; + if (error) *error = [NSError errorWithDomain:RKErrorDomain code:NSMigrationError userInfo:@{ NSLocalizedDescriptionKey: errorDescription }]; return NO; } @@ -349,7 +353,7 @@ static RKManagedObjectStore *defaultStore = nil; // Cannot complete the migration as we can't find a source model if (! sourceModel) { NSString *errorDescription = [NSString stringWithFormat:@"Migration failed: Unable to find the source managed object model used to create the %@ store at path '%@'", storeType, [storeURL path]]; - *error = [NSError errorWithDomain:RKErrorDomain code:NSMigrationMissingSourceModelError userInfo:@{ NSLocalizedDescriptionKey: errorDescription }]; + if (error) *error = [NSError errorWithDomain:RKErrorDomain code:NSMigrationMissingSourceModelError userInfo:@{ NSLocalizedDescriptionKey: errorDescription }]; return NO; } @@ -362,8 +366,11 @@ static RKManagedObjectStore *defaultStore = nil; RKLogError(@"%@", *error); return NO; } - - NSString *UUID = (__bridge_transfer NSString*)CFUUIDCreateString(kCFAllocatorDefault, CFUUIDCreate(NULL)); + + CFUUIDRef uuid = CFUUIDCreate(kCFAllocatorDefault); + NSString *UUID = (__bridge_transfer NSString*)CFUUIDCreateString(kCFAllocatorDefault, uuid); + CFRelease(uuid); + NSString *migrationPath = [NSTemporaryDirectory() stringByAppendingFormat:@"Migration-%@.sqlite", UUID]; NSURL *migrationURL = [NSURL fileURLWithPath:migrationPath];