Permalink
Browse files

Merge branch 'master' of magicalpanda.github.com:magicalpanda/Magical…

…Record
  • Loading branch information...
2 parents 911686c + 64f8b6d commit 0a762917c3c3e8e827be950acec63452213660b9 @casademora casademora committed Dec 8, 2011
@@ -13,8 +13,6 @@
C7005F1714140FB60061B9F4 /* NSAttributeDescription+MagicalDataImport.m in Sources */ = {isa = PBXBuildFile; fileRef = C7005F1514140FB60061B9F4 /* NSAttributeDescription+MagicalDataImport.m */; };
C7005F1A14140FD30061B9F4 /* NSRelationshipDescription+MagicalDataImport.m in Sources */ = {isa = PBXBuildFile; fileRef = C7005F1914140FD30061B9F4 /* NSRelationshipDescription+MagicalDataImport.m */; };
C7005F1B14140FD30061B9F4 /* NSRelationshipDescription+MagicalDataImport.m in Sources */ = {isa = PBXBuildFile; fileRef = C7005F1914140FD30061B9F4 /* NSRelationshipDescription+MagicalDataImport.m */; };
- C7005F1E1414100F0061B9F4 /* NSDictionary+MagicalDataImport.m in Sources */ = {isa = PBXBuildFile; fileRef = C7005F1D1414100F0061B9F4 /* NSDictionary+MagicalDataImport.m */; };
- C7005F1F1414100F0061B9F4 /* NSDictionary+MagicalDataImport.m in Sources */ = {isa = PBXBuildFile; fileRef = C7005F1D1414100F0061B9F4 /* NSDictionary+MagicalDataImport.m */; };
C7005F2214153A060061B9F4 /* NSEntityDescription+MagicalDataImport.m in Sources */ = {isa = PBXBuildFile; fileRef = C7005F2114153A060061B9F4 /* NSEntityDescription+MagicalDataImport.m */; };
C7005F2314153A060061B9F4 /* NSEntityDescription+MagicalDataImport.m in Sources */ = {isa = PBXBuildFile; fileRef = C7005F2114153A060061B9F4 /* NSEntityDescription+MagicalDataImport.m */; };
C70B6E7113D0F62500709450 /* NSPersisentStoreHelperTests.m in Sources */ = {isa = PBXBuildFile; fileRef = C70B6E7013D0F62500709450 /* NSPersisentStoreHelperTests.m */; };
@@ -127,6 +125,8 @@
C7E37A78141577B800CE9BF5 /* libOCMock.a in Frameworks */ = {isa = PBXBuildFile; fileRef = C721C83B13D0C6390097AB6F /* libOCMock.a */; };
C7E37A7C14157BFE00CE9BF5 /* libOCMock.a in CopyFiles */ = {isa = PBXBuildFile; fileRef = C721C83B13D0C6390097AB6F /* libOCMock.a */; };
C7E736DF1402FE64005657C9 /* SingleEntityWithNoRelationships.json in Resources */ = {isa = PBXBuildFile; fileRef = C7E736DE1402FE64005657C9 /* SingleEntityWithNoRelationships.json */; };
+ C7F5EEB2148DC76700964607 /* NSObject+MagicalDataImport.m in Sources */ = {isa = PBXBuildFile; fileRef = C7F5EEB1148DC76700964607 /* NSObject+MagicalDataImport.m */; };
+ C7F5EEB3148DC76700964607 /* NSObject+MagicalDataImport.m in Sources */ = {isa = PBXBuildFile; fileRef = C7F5EEB1148DC76700964607 /* NSObject+MagicalDataImport.m */; };
/* End PBXBuildFile section */
/* Begin PBXBuildRule section */
@@ -184,8 +184,6 @@
C7005F1514140FB60061B9F4 /* NSAttributeDescription+MagicalDataImport.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "NSAttributeDescription+MagicalDataImport.m"; path = "DataImport/NSAttributeDescription+MagicalDataImport.m"; sourceTree = "<group>"; };
C7005F1814140FD30061B9F4 /* NSRelationshipDescription+MagicalDataImport.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "NSRelationshipDescription+MagicalDataImport.h"; path = "DataImport/NSRelationshipDescription+MagicalDataImport.h"; sourceTree = "<group>"; };
C7005F1914140FD30061B9F4 /* NSRelationshipDescription+MagicalDataImport.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "NSRelationshipDescription+MagicalDataImport.m"; path = "DataImport/NSRelationshipDescription+MagicalDataImport.m"; sourceTree = "<group>"; };
- C7005F1C1414100F0061B9F4 /* NSDictionary+MagicalDataImport.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "NSDictionary+MagicalDataImport.h"; path = "DataImport/NSDictionary+MagicalDataImport.h"; sourceTree = "<group>"; };
- C7005F1D1414100F0061B9F4 /* NSDictionary+MagicalDataImport.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "NSDictionary+MagicalDataImport.m"; path = "DataImport/NSDictionary+MagicalDataImport.m"; sourceTree = "<group>"; };
C7005F2014153A060061B9F4 /* NSEntityDescription+MagicalDataImport.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "NSEntityDescription+MagicalDataImport.h"; path = "DataImport/NSEntityDescription+MagicalDataImport.h"; sourceTree = "<group>"; };
C7005F2114153A060061B9F4 /* NSEntityDescription+MagicalDataImport.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "NSEntityDescription+MagicalDataImport.m"; path = "DataImport/NSEntityDescription+MagicalDataImport.m"; sourceTree = "<group>"; };
C70B6E6F13D0F62500709450 /* NSPersisentStoreHelperTests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = NSPersisentStoreHelperTests.h; path = "Unit Tests/NSPersisentStoreHelperTests.h"; sourceTree = "<group>"; };
@@ -346,6 +344,8 @@
C7C9A38913F4524B002C5B0C /* SingleEntityRelatedToMappedEntityUsingMappedPrimaryKey.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SingleEntityRelatedToMappedEntityUsingMappedPrimaryKey.m; sourceTree = "<group>"; };
C7C9A38C13F45438002C5B0C /* ImportSingleEntityRelatedToMappedEntityUsingMappedPrimaryKeyTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ImportSingleEntityRelatedToMappedEntityUsingMappedPrimaryKeyTests.m; path = "Unit Tests/ImportSingleEntityRelatedToMappedEntityUsingMappedPrimaryKeyTests.m"; sourceTree = "<group>"; };
C7E736DE1402FE64005657C9 /* SingleEntityWithNoRelationships.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = SingleEntityWithNoRelationships.json; path = "Unit Tests/Fixtures/SingleEntityWithNoRelationships.json"; sourceTree = "<group>"; };
+ C7F5EEB0148DC76700964607 /* NSObject+MagicalDataImport.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "NSObject+MagicalDataImport.h"; path = "DataImport/NSObject+MagicalDataImport.h"; sourceTree = "<group>"; };
+ C7F5EEB1148DC76700964607 /* NSObject+MagicalDataImport.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "NSObject+MagicalDataImport.m"; path = "DataImport/NSObject+MagicalDataImport.m"; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -380,6 +380,8 @@
C7005F0E14140F690061B9F4 /* Data Import */ = {
isa = PBXGroup;
children = (
+ C7F5EEB0148DC76700964607 /* NSObject+MagicalDataImport.h */,
+ C7F5EEB1148DC76700964607 /* NSObject+MagicalDataImport.m */,
C75A4E7113D0D88D00790CEB /* NSManagedObject+MagicalDataImport.h */,
C75A4E7213D0D88D00790CEB /* NSManagedObject+MagicalDataImport.m */,
C7005F1014140F9B0061B9F4 /* NSNumber+MagicalDataImport.h */,
@@ -388,8 +390,6 @@
C7005F1514140FB60061B9F4 /* NSAttributeDescription+MagicalDataImport.m */,
C7005F1814140FD30061B9F4 /* NSRelationshipDescription+MagicalDataImport.h */,
C7005F1914140FD30061B9F4 /* NSRelationshipDescription+MagicalDataImport.m */,
- C7005F1C1414100F0061B9F4 /* NSDictionary+MagicalDataImport.h */,
- C7005F1D1414100F0061B9F4 /* NSDictionary+MagicalDataImport.m */,
C7005F2014153A060061B9F4 /* NSEntityDescription+MagicalDataImport.h */,
C7005F2114153A060061B9F4 /* NSEntityDescription+MagicalDataImport.m */,
);
@@ -965,8 +965,8 @@
C7005F1214140F9B0061B9F4 /* NSNumber+MagicalDataImport.m in Sources */,
C7005F1614140FB60061B9F4 /* NSAttributeDescription+MagicalDataImport.m in Sources */,
C7005F1A14140FD30061B9F4 /* NSRelationshipDescription+MagicalDataImport.m in Sources */,
- C7005F1E1414100F0061B9F4 /* NSDictionary+MagicalDataImport.m in Sources */,
C7005F2214153A060061B9F4 /* NSEntityDescription+MagicalDataImport.m in Sources */,
+ C7F5EEB2148DC76700964607 /* NSObject+MagicalDataImport.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -1026,8 +1026,8 @@
C7005F1314140F9B0061B9F4 /* NSNumber+MagicalDataImport.m in Sources */,
C7005F1714140FB60061B9F4 /* NSAttributeDescription+MagicalDataImport.m in Sources */,
C7005F1B14140FD30061B9F4 /* NSRelationshipDescription+MagicalDataImport.m in Sources */,
- C7005F1F1414100F0061B9F4 /* NSDictionary+MagicalDataImport.m in Sources */,
C7005F2314153A060061B9F4 /* NSEntityDescription+MagicalDataImport.m in Sources */,
+ C7F5EEB3148DC76700964607 /* NSObject+MagicalDataImport.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -14,7 +14,9 @@ extern NSString * const kMagicalRecordDidMergeChangesFromiCloudNotification;
- (void) MR_observeContext:(NSManagedObjectContext *)otherContext;
- (void) MR_stopObservingContext:(NSManagedObjectContext *)otherContext;
- (void) MR_observeContextOnMainThread:(NSManagedObjectContext *)otherContext;
+
- (void) MR_observeiCloudChangesInCoordinator:(NSPersistentStoreCoordinator *)coordinator;
+- (void) MR_stopObservingiCloudChangesInCoordinator:(NSPersistentStoreCoordinator *)coordinator;
- (BOOL) MR_save;
@@ -31,11 +31,14 @@ + (NSManagedObjectContext *)MR_defaultContext
+ (void) MR_setDefaultContext:(NSManagedObjectContext *)moc
{
-#ifndef NS_AUTOMATED_REFCOUNT_UNAVAILABLE
- [moc retain];
- [defaultManageObjectContext_ release];
-#endif
+ NSPersistentStoreCoordinator *coordinator = [NSPersistentStoreCoordinator MR_defaultStoreCoordinator];
+ [defaultManageObjectContext_ MR_stopObservingiCloudChangesInCoordinator:coordinator];
+
+ MR_RETAIN(moc);
+ MR_RELEASE(defaultManageObjectContext_);
+
defaultManageObjectContext_ = moc;
+ [defaultManageObjectContext_ MR_observeiCloudChangesInCoordinator:coordinator];
}
+ (void)MR_resetDefaultContext
@@ -88,11 +91,21 @@ - (void) MR_observeiCloudChangesInCoordinator:(NSPersistentStoreCoordinator *)co
}
+- (void) MR_stopObservingiCloudChangesInCoordinator:(NSPersistentStoreCoordinator *)coordinator;
+{
+ [[NSNotificationCenter defaultCenter] removeObserver:self
+ name:NSPersistentStoreDidImportUbiquitousContentChangesNotification
+ object:coordinator];
+}
+
- (void) MR_mergeChangesFromiCloud:(NSNotification *)notification;
{
[self performBlock:^{
- MRLog(@"Merging Changes from iCloud");
+ MRLog(@"Merging changes From iCloud %@context%@",
+ self == [NSManagedObjectContext MR_defaultContext] ? @"*** DEFAULT *** " : @"",
+ ([NSThread isMainThread] ? @" *** on Main Thread ***" : @""));
+
[self mergeChangesFromContextDidSaveNotification:notification];
[[NSNotificationCenter defaultCenter] postNotificationName:kMagicalRecordDidMergeChangesFromiCloudNotification
@@ -167,7 +180,7 @@ - (BOOL) MR_saveWithErrorHandler:(void (^)(NSError *))errorCallback;
- (void) MR_saveWrapper;
{
-#ifdef NS_AUTOMATED_REFCOUNT_UNAVAILABLE
+#if MR_USE_ARC
@autoreleasepool
{
[self MR_save];
@@ -246,8 +259,11 @@ + (NSManagedObjectContext *) MR_contextWithStoreCoordinator:(NSPersistentStoreCo
if (coordinator != nil)
{
MRLog(@"Creating MOContext %@", [NSThread isMainThread] ? @" *** On Main Thread ***" : @"");
- context = [[NSManagedObjectContext alloc] init];
- [context setPersistentStoreCoordinator:coordinator];
+ context = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType];
+ [context performBlockAndWait:^{
+ [context setPersistentStoreCoordinator:coordinator];
+ }];
+
MR_AUTORELEASE(context);
}
return context;
@@ -25,10 +25,8 @@ + (NSManagedObjectModel *) MR_defaultManagedObjectModel
+ (void) MR_setDefaultManagedObjectModel:(NSManagedObjectModel *)newDefaultModel
{
-#ifndef NS_AUTOMATED_REFCOUNT_UNAVAILABLE
- [newDefaultModel retain];
- [defaultManagedObjectModel_ release];
-#endif
+ MR_RETAIN(newDefaultModel);
+ MR_RELEASE(defaultManagedObjectModel_);
defaultManagedObjectModel_ = newDefaultModel;
}
@@ -22,10 +22,8 @@ + (NSPersistentStore *) MR_defaultPersistentStore
+ (void) MR_setDefaultPersistentStore:(NSPersistentStore *) store
{
-#ifndef NS_AUTOMATED_REFCOUNT_UNAVAILABLE
- [store retain];
- [defaultPersistentStore_ release];
-#endif
+ MR_RETAIN(store);
+ MR_RELEASE(defaultPersistentStore_);
defaultPersistentStore_ = store;
}
@@ -22,13 +22,14 @@ extern NSString * const kMagicalRecordPSCDidCompleteiCloudSetupNotification;
+ (NSPersistentStoreCoordinator *) MR_coordinatorWithSqliteStoreNamed:(NSString *)storeFileName;
+ (NSPersistentStoreCoordinator *) MR_coordinatorWithAutoMigratingSqliteStoreNamed:(NSString *)storeFileName;
+ (NSPersistentStoreCoordinator *) MR_coordinatorWithPersitentStore:(NSPersistentStore *)persistentStore;
-+ (NSPersistentStoreCoordinator *) MR_coordinatorWithiCloudContainerID:(NSString *)containerID
- contentNameKey:(NSString *)contentNameKey
- localStoreNamed:(NSString *)localStoreName
- cloudStorePathComponent:(NSString *)subPathComponent;
++ (NSPersistentStoreCoordinator *) MR_coordinatorWithiCloudContainerID:(NSString *)containerID contentNameKey:(NSString *)contentNameKey localStoreNamed:(NSString *)localStoreName cloudStorePathComponent:(NSString *)subPathComponent;
+
++ (NSPersistentStoreCoordinator *) MR_coordinatorWithiCloudContainerID:(NSString *)containerID contentNameKey:(NSString *)contentNameKey localStoreNamed:(NSString *)localStoreName cloudStorePathComponent:(NSString *)subPathComponent completion:(void(^)(void))completionHandler;
- (NSPersistentStore *) MR_addInMemoryStore;
-- (void) MR_addAutoMigratingSqliteStoreNamed:(NSString *) storeFileName;
-- (void) MR_addSqliteStoreNamed:(id)storeFileName withOptions:(__autoreleasing NSDictionary *)options;
+- (NSPersistentStore *) MR_addAutoMigratingSqliteStoreNamed:(NSString *) storeFileName;
+- (NSPersistentStore *) MR_addSqliteStoreNamed:(id)storeFileName withOptions:(__autoreleasing NSDictionary *)options;
- (void) MR_addiCloudContainerID:(NSString *)containerID contentNameKey:(NSString *)contentNameKey localStoreNamed:(NSString *)localStoreName cloudStorePathComponent:(NSString *)subPathComponent;
+- (void) MR_addiCloudContainerID:(NSString *)containerID contentNameKey:(NSString *)contentNameKey localStoreNamed:(NSString *)localStoreName cloudStorePathComponent:(NSString *)subPathComponent completion:(void(^)(void))completionBlock;
+
@end
@@ -29,10 +29,8 @@ + (NSPersistentStoreCoordinator *) MR_defaultStoreCoordinator
+ (void) MR_setDefaultStoreCoordinator:(NSPersistentStoreCoordinator *)coordinator
{
-#ifndef NS_AUTOMATED_REFCOUNT_UNAVAILABLE
- [coordinator retain];
- [defaultCoordinator_ release];
-#endif
+ MR_RETAIN(coordinator);
+ MR_RELEASE(defaultCoordinator_);
defaultCoordinator_ = coordinator;
if (defaultCoordinator_ != nil)
@@ -60,7 +58,7 @@ - (void) MR_createPathToStoreFileIfNeccessary:(NSURL *)urlForStore
}
}
-- (void) MR_addSqliteStoreNamed:(id)storeFileName withOptions:(__autoreleasing NSDictionary *)options
+- (NSPersistentStore *) MR_addSqliteStoreNamed:(id)storeFileName withOptions:(__autoreleasing NSDictionary *)options
{
NSURL *url = [storeFileName isKindOfClass:[NSURL class]] ? storeFileName : [NSPersistentStore MR_urlForStoreName:storeFileName];
NSError *error = nil;
@@ -76,6 +74,7 @@ - (void) MR_addSqliteStoreNamed:(id)storeFileName withOptions:(__autoreleasing N
{
[MagicalRecordHelpers handleErrors:error];
}
+ return store;
}
@@ -105,10 +104,10 @@ + (NSDictionary *) MR_autoMigrationOptions;
return options;
}
-- (void) MR_addAutoMigratingSqliteStoreNamed:(NSString *) storeFileName
+- (NSPersistentStore *) MR_addAutoMigratingSqliteStoreNamed:(NSString *) storeFileName;
{
NSDictionary *options = [[self class] MR_autoMigrationOptions];
- [self MR_addSqliteStoreNamed:storeFileName withOptions:options];
+ return [self MR_addSqliteStoreNamed:storeFileName withOptions:options];
}
@@ -150,6 +149,15 @@ + (NSPersistentStoreCoordinator *) MR_newPersistentStoreCoordinator
}
- (void) MR_addiCloudContainerID:(NSString *)containerID contentNameKey:(NSString *)contentNameKey localStoreNamed:(NSString *)localStoreName cloudStorePathComponent:(NSString *)subPathComponent;
+{
+ [self MR_addiCloudContainerID:containerID
+ contentNameKey:contentNameKey
+ localStoreNamed:localStoreName
+ cloudStorePathComponent:subPathComponent
+ completion:nil];
+}
+
+- (void) MR_addiCloudContainerID:(NSString *)containerID contentNameKey:(NSString *)contentNameKey localStoreNamed:(NSString *)localStoreName cloudStorePathComponent:(NSString *)subPathComponent completion:(void(^)(void))completionBlock;
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
@@ -158,7 +166,7 @@ - (void) MR_addiCloudContainerID:(NSString *)containerID contentNameKey:(NSStrin
{
cloudURL = [cloudURL URLByAppendingPathComponent:subPathComponent];
}
-
+
NSDictionary *options = [[self class] MR_autoMigrationOptions];
if (cloudURL) //iCloud is available
{
@@ -171,12 +179,20 @@ - (void) MR_addiCloudContainerID:(NSString *)containerID contentNameKey:(NSStrin
{
MRLog(@"iCloud is not enabled");
}
+
[self lock];
[self MR_addSqliteStoreNamed:localStoreName withOptions:options];
[self unlock];
dispatch_async(dispatch_get_main_queue(), ^{
- MRLog(@"iCloud Store Enabled: %@", [MagicalRecordHelpers currentStack]);
+ if ([NSPersistentStore MR_defaultPersistentStore] == nil)
+ {
+ [NSPersistentStore MR_setDefaultPersistentStore:[[self persistentStores] objectAtIndex:0]];
+ }
+ if (completionBlock)
+ {
+ completionBlock();
+ }
[[NSNotificationCenter defaultCenter] postNotificationName:kMagicalRecordPSCDidCompleteiCloudSetupNotification object:nil];
});
});
@@ -186,14 +202,28 @@ + (NSPersistentStoreCoordinator *) MR_coordinatorWithiCloudContainerID:(NSString
contentNameKey:(NSString *)contentNameKey
localStoreNamed:(NSString *)localStoreName
cloudStorePathComponent:(NSString *)subPathComponent;
+{
+ return [self MR_coordinatorWithiCloudContainerID:containerID
+ contentNameKey:contentNameKey
+ localStoreNamed:localStoreName
+ cloudStorePathComponent:subPathComponent
+ completion:nil];
+}
+
++ (NSPersistentStoreCoordinator *) MR_coordinatorWithiCloudContainerID:(NSString *)containerID
+ contentNameKey:(NSString *)contentNameKey
+ localStoreNamed:(NSString *)localStoreName
+ cloudStorePathComponent:(NSString *)subPathComponent
+ completion:(void(^)(void))completionHandler;
{
NSManagedObjectModel *model = [NSManagedObjectModel MR_defaultManagedObjectModel];
NSPersistentStoreCoordinator *psc = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:model];
[psc MR_addiCloudContainerID:containerID
contentNameKey:contentNameKey
localStoreNamed:localStoreName
- cloudStorePathComponent:subPathComponent];
+ cloudStorePathComponent:subPathComponent
+ completion:completionHandler];
MR_AUTORELEASE(psc);
return psc;
Oops, something went wrong.

0 comments on commit 0a76291

Please sign in to comment.