Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

NSAtomicStore is added! #421

Closed
wants to merge 2 commits into from

3 participants

@ilin-in

Now you can setup Core Data stack with manual Store Type name. That
means you can use MagicalRecord with NSAtomicStore easily.

@ilin-in ilin-in NSAtomicStore added
Now you can setup Core Data stack with manualy Store Type name. That
means you can use MagicalRecord with NSAtomicStore easily.
b30bb2b
@casademora

Let's not make a dictionary of parameters :( This is not very discoverable.

ok. What is better to use here define new class or struct? performSelector:withObject:afterDelay: doesn't accept 2 params :(

I'm have fixed this issue in b30bb2b by replacing performSelector:withObject:afterDelay: to dispatch_after

@ilin-in ilin-in Array params have been removed
`performSelector:withObject:afterDelay` replaced to `dispatch_after` in
same time
2e986ac
@tonyarnold
Owner

@ilin-in, would you mind resubmitting this pull request against the develop branch? We try not to merge changes directly to the stable master branch if we can avoid it.

@ilin-in

@tonyarnold yes, sure.

@tonyarnold tonyarnold was assigned
@tonyarnold
Owner

Closing in favour of #423.

@tonyarnold tonyarnold closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 20, 2013
  1. @ilin-in

    NSAtomicStore added

    ilin-in authored
    Now you can setup Core Data stack with manualy Store Type name. That
    means you can use MagicalRecord with NSAtomicStore easily.
Commits on Feb 21, 2013
  1. @ilin-in

    Array params have been removed

    ilin-in authored
    `performSelector:withObject:afterDelay` replaced to `dispatch_after` in
    same time
This page is out of date. Refresh to see the latest.
View
4 MagicalRecord/Categories/NSPersistentStoreCoordinator+MagicalRecord.h
@@ -20,7 +20,9 @@ extern NSString * const kMagicalRecordPSCDidCompleteiCloudSetupNotification;
+ (NSPersistentStoreCoordinator *) MR_newPersistentStoreCoordinator NS_RETURNS_RETAINED;
+ (NSPersistentStoreCoordinator *) MR_coordinatorWithSqliteStoreNamed:(NSString *)storeFileName;
++ (NSPersistentStoreCoordinator *) MR_coordinatorWithCustomStoreNamed:(NSString *)storeFileName storeType:(NSString*)storeType;
+ (NSPersistentStoreCoordinator *) MR_coordinatorWithAutoMigratingSqliteStoreNamed:(NSString *)storeFileName;
++ (NSPersistentStoreCoordinator *) MR_coordinatorWithAutoMigratingCustomStoreNamed:(NSString *) storeFileName storeType:(NSString*) storeType;
+ (NSPersistentStoreCoordinator *) MR_coordinatorWithPersistentStore:(NSPersistentStore *)persistentStore;
+ (NSPersistentStoreCoordinator *) MR_coordinatorWithiCloudContainerID:(NSString *)containerID contentNameKey:(NSString *)contentNameKey localStoreNamed:(NSString *)localStoreName cloudStorePathComponent:(NSString *)subPathComponent;
@@ -28,7 +30,9 @@ extern NSString * const kMagicalRecordPSCDidCompleteiCloudSetupNotification;
- (NSPersistentStore *) MR_addInMemoryStore;
- (NSPersistentStore *) MR_addAutoMigratingSqliteStoreNamed:(NSString *) storeFileName;
+- (NSPersistentStore *) MR_addAutoMigratingCustomStoreNamed:(NSString*)fileName storeType:(NSString*)storeTypeName;
- (NSPersistentStore *) MR_addSqliteStoreNamed:(id)storeFileName withOptions:(__autoreleasing NSDictionary *)options;
+- (NSPersistentStore *) MR_addCustomStoreNamed:(id)storeFileName withOptions:(__autoreleasing NSDictionary *)options storeType:(NSString*)storeType;
- (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;
View
64 MagicalRecord/Categories/NSPersistentStoreCoordinator+MagicalRecord.m
@@ -64,12 +64,18 @@ - (void) MR_createPathToStoreFileIfNeccessary:(NSURL *)urlForStore
- (NSPersistentStore *) MR_addSqliteStoreNamed:(id)storeFileName withOptions:(__autoreleasing NSDictionary *)options
{
+ return [self MR_addCustomStoreNamed:storeFileName withOptions:options storeType:NSSQLiteStoreType];
+}
+
+// For use MagicalRecord with NSAtomicStore or other store types
+- (NSPersistentStore *) MR_addCustomStoreNamed:(id)storeFileName withOptions:(__autoreleasing NSDictionary *)options storeType:(NSString*)storeType
+{
NSURL *url = [storeFileName isKindOfClass:[NSURL class]] ? storeFileName : [NSPersistentStore MR_urlForStoreName:storeFileName];
NSError *error = nil;
[self MR_createPathToStoreFileIfNeccessary:url];
- NSPersistentStore *store = [self addPersistentStoreWithType:NSSQLiteStoreType
+ NSPersistentStore *store = [self addPersistentStoreWithType:storeType
configuration:nil
URL:url
options:options
@@ -82,11 +88,11 @@ - (NSPersistentStore *) MR_addSqliteStoreNamed:(id)storeFileName withOptions:(__
{
// Could not open the database, so... kill it!
[[NSFileManager defaultManager] removeItemAtURL:url error:nil];
-
+
MRLog(@"Removed incompatible model version: %@", [url lastPathComponent]);
// Try one more time to create the store
- store = [self addPersistentStoreWithType:NSSQLiteStoreType
+ store = [self addPersistentStoreWithType:storeType
configuration:nil
URL:url
options:options
@@ -97,7 +103,7 @@ - (NSPersistentStore *) MR_addSqliteStoreNamed:(id)storeFileName withOptions:(__
error = nil;
}
}
-
+
[MagicalRecord handleErrors:error];
}
return store;
@@ -141,22 +147,50 @@ - (NSPersistentStore *) MR_addAutoMigratingSqliteStoreNamed:(NSString *) storeFi
return [self MR_addSqliteStoreNamed:storeFileName withOptions:options];
}
+- (NSPersistentStore *) MR_addAutoMigratingCustomStoreNamed:(NSString*)fileName storeType:(NSString*)storeTypeName {
+ NSDictionary *options = [[self class] MR_autoMigrationOptions];
+ return [self MR_addCustomStoreNamed:fileName withOptions:options storeType:storeTypeName];
+}
#pragma mark - Public Class Methods
-
-+ (NSPersistentStoreCoordinator *) MR_coordinatorWithAutoMigratingSqliteStoreNamed:(NSString *) storeFileName
-{
++ (NSPersistentStoreCoordinator *) MR_coordinatorWithAutoMigratingSqliteStoreNamed:(NSString *) storeFileName {
NSManagedObjectModel *model = [NSManagedObjectModel MR_defaultManagedObjectModel];
NSPersistentStoreCoordinator *coordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:model];
[coordinator MR_addAutoMigratingSqliteStoreNamed:storeFileName];
//HACK: lame solution to fix automigration error "Migration failed after first pass"
- if ([[coordinator persistentStores] count] == 0)
+ if ([[coordinator persistentStores] count] == 0)
{
[coordinator performSelector:@selector(MR_addAutoMigratingSqliteStoreNamed:) withObject:storeFileName afterDelay:0.5];
}
+
+ return coordinator;
+}
+
++ (NSPersistentStoreCoordinator *) MR_coordinatorWithAutoMigratingCustomStoreNamed:(NSString *) storeFileName storeType:(NSString*) storeType
+{
+ NSManagedObjectModel *model = [NSManagedObjectModel MR_defaultManagedObjectModel];
+ NSPersistentStoreCoordinator *coordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:model];
+
+ if (!storeType) {
+ MRLog(@"Loading default SQLite store type");
+ storeType = NSSQLiteStoreType;
+ }
+
+ [coordinator MR_addAutoMigratingCustomStoreNamed:storeFileName storeType:storeType];
+
+ //HACK: lame solution to fix automigration error "Migration failed after first pass"
+ if ([[coordinator persistentStores] count] == 0)
+ {
+ int64_t delay = 0.5;
+ dispatch_time_t time = dispatch_time(DISPATCH_TIME_NOW, delay * NSEC_PER_SEC);
+ dispatch_after(time, dispatch_get_current_queue(), ^(void){
+ [coordinator performSelector:@selector(MR_addAutoMigratingSqliteStoreNamed:) withObject:storeFileName afterDelay:0.5];
+ [coordinator MR_addAutoMigratingCustomStoreNamed:storeFileName storeType:storeType];
+ });
+ }
return coordinator;
}
@@ -271,6 +305,20 @@ + (NSPersistentStoreCoordinator *) MR_coordinatorWithPersistentStore:(NSPersiste
return psc;
}
++ (NSPersistentStoreCoordinator *) MR_coordinatorWithCustomStoreNamed:(NSString *)storeFileName storeType:(NSString*)storeType
+{
+ if (!storeType) {
+ MRLog(@"Loading default SQLite store type");
+ storeType = NSSQLiteStoreType;
+ }
+
+ NSManagedObjectModel *model = [NSManagedObjectModel MR_defaultManagedObjectModel];
+ NSPersistentStoreCoordinator *psc = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:model];
+
+ [psc MR_addCustomStoreNamed:storeFileName withOptions:nil storeType:storeType];
+ return psc;
+}
+
+ (NSPersistentStoreCoordinator *) MR_coordinatorWithSqliteStoreNamed:(NSString *)storeFileName withOptions:(NSDictionary *)options
{
NSManagedObjectModel *model = [NSManagedObjectModel MR_defaultManagedObjectModel];
View
4 MagicalRecord/Core/MagicalRecord+Setup.h
@@ -13,9 +13,13 @@
+ (void) setupCoreDataStack;
+ (void) setupCoreDataStackWithInMemoryStore;
+ (void) setupAutoMigratingCoreDataStack;
++ (void) setupCoreDataStackWithType:(NSString*)storeType;
++ (void) setupAutoMigratingCoreDataStackWithType:(NSString*)storeType;
+ (void) setupCoreDataStackWithStoreNamed:(NSString *)storeName;
++ (void) setupCoreDataStackWithStoreNamed:(NSString *)storeName andCustomStoreType:(NSString*)storeType;
+ (void) setupCoreDataStackWithAutoMigratingSqliteStoreNamed:(NSString *)storeName;
++ (void) setupCoreDataStackWithAutoMigratingCustomStoreNamed:(NSString *)storeName andCustomStoreType:(NSString*)storeType;
@end
View
30 MagicalRecord/Core/MagicalRecord+Setup.m
@@ -23,26 +23,48 @@ + (void) setupAutoMigratingCoreDataStack
[self setupCoreDataStackWithAutoMigratingSqliteStoreNamed:[self defaultStoreName]];
}
-+ (void) setupCoreDataStackWithStoreNamed:(NSString *)storeName
++ (void) setupAutoMigratingCoreDataStackWithType:(NSString*)storeType
+{
+ [self setupCoreDataStackWithAutoMigratingCustomStoreNamed:[self defaultStoreName] andCustomStoreType:storeType];
+}
+
++ (void) setupCoreDataStackWithType:(NSString*)storeType
{
+ [self setupCoreDataStackWithStoreNamed:[self defaultStoreName] andCustomStoreType:storeType];
+}
+
++ (void) setupCoreDataStackWithStoreNamed:(NSString *)storeName andCustomStoreType:(NSString*)storeType {
if ([NSPersistentStoreCoordinator MR_defaultStoreCoordinator] != nil) return;
- NSPersistentStoreCoordinator *coordinator = [NSPersistentStoreCoordinator MR_coordinatorWithSqliteStoreNamed:storeName];
+ NSPersistentStoreCoordinator *coordinator = [NSPersistentStoreCoordinator MR_coordinatorWithCustomStoreNamed:storeName storeType:storeType];
[NSPersistentStoreCoordinator MR_setDefaultStoreCoordinator:coordinator];
[NSManagedObjectContext MR_initializeDefaultContextWithCoordinator:coordinator];
}
-+ (void) setupCoreDataStackWithAutoMigratingSqliteStoreNamed:(NSString *)storeName
++ (void) setupCoreDataStackWithStoreNamed:(NSString *)storeName
+{
+ [self setupCoreDataStackWithStoreNamed:storeName andCustomStoreType:nil];
+}
+
++ (void) setupCoreDataStackWithAutoMigratingCustomStoreNamed:(NSString *)storeName andCustomStoreType:(NSString*)storeType
{
if ([NSPersistentStoreCoordinator MR_defaultStoreCoordinator] != nil) return;
- NSPersistentStoreCoordinator *coordinator = [NSPersistentStoreCoordinator MR_coordinatorWithAutoMigratingSqliteStoreNamed:storeName];
+ if (!storeName) {
+ storeName = [self defaultStoreName];
+ }
+ NSPersistentStoreCoordinator *coordinator = [NSPersistentStoreCoordinator MR_coordinatorWithAutoMigratingCustomStoreNamed:storeName storeType:storeType];
[NSPersistentStoreCoordinator MR_setDefaultStoreCoordinator:coordinator];
[NSManagedObjectContext MR_initializeDefaultContextWithCoordinator:coordinator];
}
++ (void) setupCoreDataStackWithAutoMigratingSqliteStoreNamed:(NSString *)storeName
+{
+ [self setupCoreDataStackWithAutoMigratingCustomStoreNamed:storeName andCustomStoreType:NSSQLiteStoreType];
+}
+
+ (void) setupCoreDataStackWithInMemoryStore;
{
if ([NSPersistentStoreCoordinator MR_defaultStoreCoordinator] != nil) return;
Something went wrong with that request. Please try again.