diff --git a/Mac App Unit Tests/Mac App Unit Tests-Prefix.pch b/Mac App Unit Tests/Mac App Unit Tests-Prefix.pch index 487e390..9b8069c 100644 --- a/Mac App Unit Tests/Mac App Unit Tests-Prefix.pch +++ b/Mac App Unit Tests/Mac App Unit Tests-Prefix.pch @@ -9,6 +9,7 @@ #define HC_SHORTHAND #import + #define MR_SHORTHAND #import "CoreData+MagicalRecord.h" #import "FixtureHelpers.h" #endif diff --git a/Source/Categories/NSManagedObject+MagicalRecord.h b/Source/Categories/NSManagedObject+MagicalRecord.h index 0276100..f1c8a0d 100644 --- a/Source/Categories/NSManagedObject+MagicalRecord.h +++ b/Source/Categories/NSManagedObject+MagicalRecord.h @@ -108,33 +108,34 @@ #endif - -#ifdef MR_SHORTHAND - -#define defaultBatchSize MR_defaultBatchSize -#define setDefaultBatchSize MR_setDefaultBatchSize - -#define createFetchRequest MR_createFetchRequest -#define executeFetchRequest MR_executeFetchRequest - -#define requestAll MR_requestAll -#define trucateAll MR_truncateAll - -#define numberOfEntities MR_numberOfEntities -#define hasAtLeastOneEntity MR_hasAtLeastOneEntity - -#define findAll MR_findAll -#define findByAttribute MR_findByAttribute - -#define findFirst MR_findFirst -#define findFirstByAttribute MR_findFirstByAttribute - -#define fetchAllSortedBy MR_fetchAllSortedBy -#define fetchRequest MR_fetchRequest - -#define inContext MR_inContext -#define inThreadContext MR_inThreadContext - -#endif - @end + +/* + #ifdef MR_SHORTHAND + + #define defaultBatchSize MR_defaultBatchSize + #define setDefaultBatchSize MR_setDefaultBatchSize + + #define createFetchRequest MR_createFetchRequest + #define executeFetchRequest MR_executeFetchRequest + + #define requestAll MR_requestAll + #define trucateAll MR_truncateAll + + #define numberOfEntities MR_numberOfEntities + #define hasAtLeastOneEntity MR_hasAtLeastOneEntity + + #define findAll MR_findAll + #define findByAttribute MR_findByAttribute + + #define findFirst MR_findFirst + #define findFirstByAttribute MR_findFirstByAttribute + + #define fetchAllSortedBy MR_fetchAllSortedBy + #define fetchRequest MR_fetchRequest + + #define inContext MR_inContext + #define inThreadContext MR_inThreadContext + + #endif + */ diff --git a/Source/Categories/NSManagedObjectContext+MagicalRecord.h b/Source/Categories/NSManagedObjectContext+MagicalRecord.h index 59b5990..3d639f2 100644 --- a/Source/Categories/NSManagedObjectContext+MagicalRecord.h +++ b/Source/Categories/NSManagedObjectContext+MagicalRecord.h @@ -39,7 +39,7 @@ @end - +/* #ifdef MR_SHORTHAND #define observeContext MR_observeContext @@ -56,10 +56,12 @@ #define setNotifiesMainContextOnSave MR_setNotifiesMainContextOnSave #define notifiesMainContextonSave MR_notifiesMainContextonSave -#define context] MR_context] +//#define context] MR_context] #define contextForCurrentThread MR_contextForCurrentThread #define contextThatNotifiesDefaultContextOnMainThread MR_contextThatNotifiesDefaultContextOnMainThread #define contextWithStoreCoordinator MR_contextWithStoreCoodinator -#endif \ No newline at end of file +#endif + +*/ diff --git a/Source/Categories/NSManagedObjectContext+MagicalRecord.m b/Source/Categories/NSManagedObjectContext+MagicalRecord.m index 0328fcc..0ecda9b 100644 --- a/Source/Categories/NSManagedObjectContext+MagicalRecord.m +++ b/Source/Categories/NSManagedObjectContext+MagicalRecord.m @@ -224,7 +224,7 @@ static NSString const * kMagicalRecordManagedObjectContextKey = @"MagicalRecord_ + (NSManagedObjectContext *) context { - return [self contextWithStoreCoordinator:[NSPersistentStoreCoordinator defaultStoreCoordinator]]; + return [self contextWithStoreCoordinator:[NSPersistentStoreCoordinator MR_defaultStoreCoordinator]]; } + (NSManagedObjectContext *) contextThatNotifiesDefaultContextOnMainThread diff --git a/Source/Categories/NSManagedObjectModel+MagicalRecord.h b/Source/Categories/NSManagedObjectModel+MagicalRecord.h index 71e5392..4bda170 100644 --- a/Source/Categories/NSManagedObjectModel+MagicalRecord.h +++ b/Source/Categories/NSManagedObjectModel+MagicalRecord.h @@ -20,6 +20,7 @@ @end +/* #ifdef MR_SHORTHAND #define defaultManagedObjectModel MR_defaultManagedObjectModel @@ -28,4 +29,5 @@ #define managedObectModelNamed MR_managedObjectModelNamed #define newModelNamed MR_newModelNamed -#endif \ No newline at end of file +#endif +*/ \ No newline at end of file diff --git a/Source/Categories/NSPersistentStore+MagicalRecord.h b/Source/Categories/NSPersistentStore+MagicalRecord.h index 9a5ea50..3c63b65 100644 --- a/Source/Categories/NSPersistentStore+MagicalRecord.h +++ b/Source/Categories/NSPersistentStore+MagicalRecord.h @@ -12,12 +12,12 @@ extern NSString * const kMagicalRecordDefaultStoreFileName; @interface NSPersistentStore (MagicalRecord) -+ (NSURL *) defaultLocalStoreUrl; ++ (NSURL *) MR_defaultLocalStoreUrl; -+ (NSPersistentStore *) defaultPersistentStore; -+ (void) setDefaultPersistentStore:(NSPersistentStore *) store; ++ (NSPersistentStore *) MR_defaultPersistentStore; ++ (void) MR_setDefaultPersistentStore:(NSPersistentStore *) store; -+ (NSURL *) urlForStoreName:(NSString *)storeFileName; ++ (NSURL *) MR_urlForStoreName:(NSString *)storeFileName; @end diff --git a/Source/Categories/NSPersistentStore+MagicalRecord.m b/Source/Categories/NSPersistentStore+MagicalRecord.m index 5957e87..1a96421 100644 --- a/Source/Categories/NSPersistentStore+MagicalRecord.m +++ b/Source/Categories/NSPersistentStore+MagicalRecord.m @@ -10,47 +10,47 @@ NSString * const kMagicalRecordDefaultStoreFileName = @"CoreDataStore.sqlite"; -static NSPersistentStore *defaultPersistentStore = nil; +static NSPersistentStore *defaultPersistentStore_ = nil; @implementation NSPersistentStore (MagicalRecord) -+ (NSPersistentStore *) defaultPersistentStore ++ (NSPersistentStore *) MR_defaultPersistentStore { - return defaultPersistentStore; + return defaultPersistentStore_; } -+ (void) setDefaultPersistentStore:(NSPersistentStore *) store ++ (void) MR_setDefaultPersistentStore:(NSPersistentStore *) store { - defaultPersistentStore = store; + defaultPersistentStore_ = store; } -+ (NSString *) directory:(int) type ++ (NSString *) MR_directory:(int) type { return [NSSearchPathForDirectoriesInDomains(type, NSUserDomainMask, YES) lastObject]; } -+ (NSString *)applicationDocumentsDirectory ++ (NSString *)MR_applicationDocumentsDirectory { - return [self directory:NSDocumentDirectory]; + return [self MR_directory:NSDocumentDirectory]; } -+ (NSString *)applicationLibraryDirectory ++ (NSString *)MR_applicationLibraryDirectory { #if !TARGET_OS_IPHONE && !TARGET_IPHONE_SIMULATOR NSString *applicationName = [[[NSBundle mainBundle] infoDictionary] valueForKey:(NSString *)kCFBundleNameKey]; - return [[self directory:NSApplicationSupportDirectory] stringByAppendingPathComponent:applicationName]; + return [[self MR_directory:NSApplicationSupportDirectory] stringByAppendingPathComponent:applicationName]; #else - return [self directory:NSLibraryDirectory]; + return [self MR_directory:NSLibraryDirectory]; #endif } -+ (NSURL *) urlForStoreName:(NSString *)storeFileName ++ (NSURL *) MR_urlForStoreName:(NSString *)storeFileName { - NSArray *paths = [NSArray arrayWithObjects:[self applicationDocumentsDirectory], [self applicationLibraryDirectory], nil]; + NSArray *paths = [NSArray arrayWithObjects:[self MR_applicationDocumentsDirectory], [self MR_applicationLibraryDirectory], nil]; NSFileManager *fm = [[NSFileManager alloc] init]; for (NSString *path in paths) @@ -63,12 +63,12 @@ static NSPersistentStore *defaultPersistentStore = nil; } //set default url - return [NSURL fileURLWithPath:[[self applicationLibraryDirectory] stringByAppendingPathComponent:storeFileName]]; + return [NSURL fileURLWithPath:[[self MR_applicationLibraryDirectory] stringByAppendingPathComponent:storeFileName]]; } -+ (NSURL *)defaultLocalStoreUrl ++ (NSURL *)MR_defaultLocalStoreUrl { - return [self urlForStoreName:kMagicalRecordDefaultStoreFileName]; + return [self MR_urlForStoreName:kMagicalRecordDefaultStoreFileName]; } @end diff --git a/Source/Categories/NSPersistentStoreCoordinator+MagicalRecord.h b/Source/Categories/NSPersistentStoreCoordinator+MagicalRecord.h index 33b44a7..31803eb 100644 --- a/Source/Categories/NSPersistentStoreCoordinator+MagicalRecord.h +++ b/Source/Categories/NSPersistentStoreCoordinator+MagicalRecord.h @@ -11,18 +11,18 @@ @interface NSPersistentStoreCoordinator (MagicalRecord) -+ (NSPersistentStoreCoordinator *) defaultStoreCoordinator; -+ (void) setDefaultStoreCoordinator:(NSPersistentStoreCoordinator *)coordinator; ++ (NSPersistentStoreCoordinator *) MR_defaultStoreCoordinator; ++ (void) MR_setDefaultStoreCoordinator:(NSPersistentStoreCoordinator *)coordinator; -+ (NSPersistentStoreCoordinator *) coordinatorWithInMemoryStore; ++ (NSPersistentStoreCoordinator *) MR_coordinatorWithInMemoryStore; -+ (NSPersistentStoreCoordinator *)newPersistentStoreCoordinator; ++ (NSPersistentStoreCoordinator *) MR_newPersistentStoreCoordinator; -+ (NSPersistentStoreCoordinator *) coordinatorWithSqliteStoreNamed:(NSString *)storeFileName; -+ (NSPersistentStoreCoordinator *) coordinatorWithAutoMigratingSqliteStoreNamed:(NSString *) storeFileName; -+ (NSPersistentStoreCoordinator *) coordinatorWithPersitentStore:(NSPersistentStore *)persistentStore; ++ (NSPersistentStoreCoordinator *) MR_coordinatorWithSqliteStoreNamed:(NSString *)storeFileName; ++ (NSPersistentStoreCoordinator *) MR_coordinatorWithAutoMigratingSqliteStoreNamed:(NSString *) storeFileName; ++ (NSPersistentStoreCoordinator *) MR_coordinatorWithPersitentStore:(NSPersistentStore *)persistentStore; -- (NSPersistentStore *) addInMemoryStore; +- (NSPersistentStore *) MR_addInMemoryStore; @end diff --git a/Source/Categories/NSPersistentStoreCoordinator+MagicalRecord.m b/Source/Categories/NSPersistentStoreCoordinator+MagicalRecord.m index b2d7049..0a71c60 100644 --- a/Source/Categories/NSPersistentStoreCoordinator+MagicalRecord.m +++ b/Source/Categories/NSPersistentStoreCoordinator+MagicalRecord.m @@ -15,24 +15,24 @@ static NSPersistentStoreCoordinator *defaultCoordinator = nil; @implementation NSPersistentStoreCoordinator (MagicalRecord) -+ (NSPersistentStoreCoordinator *) defaultStoreCoordinator ++ (NSPersistentStoreCoordinator *) MR_defaultStoreCoordinator { @synchronized (self) { if (defaultCoordinator == nil) { - defaultCoordinator = [self newPersistentStoreCoordinator]; + defaultCoordinator = [self MR_newPersistentStoreCoordinator]; } } return defaultCoordinator; } -+ (void) setDefaultStoreCoordinator:(NSPersistentStoreCoordinator *)coordinator ++ (void) MR_setDefaultStoreCoordinator:(NSPersistentStoreCoordinator *)coordinator { defaultCoordinator = coordinator; } -- (void) setupSqliteStoreNamed:(id)storeFileName withOptions:(NSDictionary *)options +- (void) MR_setupSqliteStoreNamed:(id)storeFileName withOptions:(NSDictionary *)options { NSURL *url = [storeFileName isKindOfClass:[NSURL class]] ? storeFileName : [NSPersistentStore urlForStoreName:storeFileName]; NSError *error = nil; @@ -48,66 +48,66 @@ static NSPersistentStoreCoordinator *defaultCoordinator = nil; [NSPersistentStore setDefaultPersistentStore:store]; } -+ (NSPersistentStoreCoordinator *) coordinatorWithPersitentStore:(NSPersistentStore *)persistentStore; ++ (NSPersistentStoreCoordinator *) MR_coordinatorWithPersitentStore:(NSPersistentStore *)persistentStore; { NSManagedObjectModel *model = [NSManagedObjectModel defaultManagedObjectModel]; NSPersistentStoreCoordinator *psc = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:model]; - [psc setupSqliteStoreNamed:[persistentStore URL] withOptions:nil]; + [psc MR_setupSqliteStoreNamed:[persistentStore URL] withOptions:nil]; return psc; } -+ (NSPersistentStoreCoordinator *) coordinatorWithSqliteStoreNamed:(NSString *)storeFileName withOptions:(NSDictionary *)options ++ (NSPersistentStoreCoordinator *) MR_coordinatorWithSqliteStoreNamed:(NSString *)storeFileName withOptions:(NSDictionary *)options { NSManagedObjectModel *model = [NSManagedObjectModel defaultManagedObjectModel]; NSPersistentStoreCoordinator *psc = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:model]; - [psc setupSqliteStoreNamed:storeFileName withOptions:options]; + [psc MR_setupSqliteStoreNamed:storeFileName withOptions:options]; return psc; } -+ (NSPersistentStoreCoordinator *) coordinatorWithSqliteStoreNamed:(NSString *)storeFileName ++ (NSPersistentStoreCoordinator *) MR_coordinatorWithSqliteStoreNamed:(NSString *)storeFileName { - return [self coordinatorWithSqliteStoreNamed:storeFileName withOptions:nil]; + return [self MR_coordinatorWithSqliteStoreNamed:storeFileName withOptions:nil]; } -- (void) setupAutoMigratingSqliteStoreNamed:(NSString *) storeFileName +- (void) MR_setupAutoMigratingSqliteStoreNamed:(NSString *) storeFileName { NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption, [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil]; - [self setupSqliteStoreNamed:storeFileName withOptions:options]; + [self MR_setupSqliteStoreNamed:storeFileName withOptions:options]; } -+ (NSPersistentStoreCoordinator *) coordinatorWithAutoMigratingSqliteStoreNamed:(NSString *) storeFileName ++ (NSPersistentStoreCoordinator *) MR_coordinatorWithAutoMigratingSqliteStoreNamed:(NSString *) storeFileName { NSManagedObjectModel *model = [NSManagedObjectModel defaultManagedObjectModel]; NSPersistentStoreCoordinator *coordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:model]; - [coordinator setupAutoMigratingSqliteStoreNamed:storeFileName]; + [coordinator MR_setupAutoMigratingSqliteStoreNamed:storeFileName]; //HACK: lame solution to fix automigration error "Migration failed after first pass" if ([[coordinator persistentStores] count] == 0) { - [coordinator performSelector:@selector(setupAutoMigratingSqliteStoreNamed:) withObject:storeFileName afterDelay:0.5]; + [coordinator performSelector:@selector(MR_setupAutoMigratingSqliteStoreNamed:) withObject:storeFileName afterDelay:0.5]; } return coordinator; } -+ (NSPersistentStoreCoordinator *) coordinatorWithInMemoryStore ++ (NSPersistentStoreCoordinator *) MR_coordinatorWithInMemoryStore { NSManagedObjectModel *model = [NSManagedObjectModel defaultManagedObjectModel]; NSPersistentStoreCoordinator *psc = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:model]; - [NSPersistentStore setDefaultPersistentStore:[psc addInMemoryStore]]; + [NSPersistentStore setDefaultPersistentStore:[psc MR_addInMemoryStore]]; return psc; } -- (NSPersistentStore *) addInMemoryStore +- (NSPersistentStore *) MR_addInMemoryStore { NSError *error = nil; NSPersistentStore *store = [self addPersistentStoreWithType:NSInMemoryStoreType @@ -122,9 +122,9 @@ static NSPersistentStoreCoordinator *defaultCoordinator = nil; return store; } -+ (NSPersistentStoreCoordinator *) newPersistentStoreCoordinator ++ (NSPersistentStoreCoordinator *) MR_newPersistentStoreCoordinator { - return [self coordinatorWithSqliteStoreNamed:kMagicalRecordDefaultStoreFileName]; + return [self MR_coordinatorWithSqliteStoreNamed:kMagicalRecordDefaultStoreFileName]; } @end diff --git a/Source/MagicalRecordHelpers.m b/Source/MagicalRecordHelpers.m index 2d174c3..238292a 100644 --- a/Source/MagicalRecordHelpers.m +++ b/Source/MagicalRecordHelpers.m @@ -17,7 +17,7 @@ static SEL errorHandlerAction = nil; [MRCoreDataAction cleanUp]; [NSManagedObjectContext setDefaultContext:nil]; [NSManagedObjectModel setDefaultManagedObjectModel:nil]; - [NSPersistentStoreCoordinator setDefaultStoreCoordinator:nil]; + [NSPersistentStoreCoordinator MR_setDefaultStoreCoordinator:nil]; [NSPersistentStore setDefaultPersistentStore:nil]; } @@ -100,8 +100,8 @@ static SEL errorHandlerAction = nil; + (void) setupCoreDataStackWithStoreNamed:(NSString *)storeName { - NSPersistentStoreCoordinator *coordinator = [NSPersistentStoreCoordinator coordinatorWithSqliteStoreNamed:storeName]; - [NSPersistentStoreCoordinator setDefaultStoreCoordinator:coordinator]; + NSPersistentStoreCoordinator *coordinator = [NSPersistentStoreCoordinator MR_coordinatorWithSqliteStoreNamed:storeName]; + [NSPersistentStoreCoordinator MR_setDefaultStoreCoordinator:coordinator]; NSManagedObjectContext *context = [NSManagedObjectContext contextWithStoreCoordinator:coordinator]; [NSManagedObjectContext setDefaultContext:context]; @@ -109,8 +109,8 @@ static SEL errorHandlerAction = nil; + (void) setupCoreDataStackWithAutoMigratingSqliteStoreNamed:(NSString *)storeName { - NSPersistentStoreCoordinator *coordinator = [NSPersistentStoreCoordinator coordinatorWithAutoMigratingSqliteStoreNamed:storeName]; - [NSPersistentStoreCoordinator setDefaultStoreCoordinator:coordinator]; + NSPersistentStoreCoordinator *coordinator = [NSPersistentStoreCoordinator MR_coordinatorWithAutoMigratingSqliteStoreNamed:storeName]; + [NSPersistentStoreCoordinator MR_setDefaultStoreCoordinator:coordinator]; NSManagedObjectContext *context = [NSManagedObjectContext contextWithStoreCoordinator:coordinator]; [NSManagedObjectContext setDefaultContext:context]; @@ -118,8 +118,8 @@ static SEL errorHandlerAction = nil; + (void) setupCoreDataStackWithInMemoryStore { - NSPersistentStoreCoordinator *coordinator = [NSPersistentStoreCoordinator coordinatorWithInMemoryStore]; - [NSPersistentStoreCoordinator setDefaultStoreCoordinator:coordinator]; + NSPersistentStoreCoordinator *coordinator = [NSPersistentStoreCoordinator MR_coordinatorWithInMemoryStore]; + [NSPersistentStoreCoordinator MR_setDefaultStoreCoordinator:coordinator]; NSManagedObjectContext *context = [NSManagedObjectContext contextWithStoreCoordinator:coordinator]; [NSManagedObjectContext setDefaultContext:context]; diff --git a/Unit Tests/MagicalRecordHelperTests.m b/Unit Tests/MagicalRecordHelperTests.m index 5132204..8ba256e 100644 --- a/Unit Tests/MagicalRecordHelperTests.m +++ b/Unit Tests/MagicalRecordHelperTests.m @@ -25,7 +25,7 @@ { assertThat([NSManagedObjectContext defaultContext], is(notNilValue())); assertThat([NSManagedObjectModel defaultManagedObjectModel], is(notNilValue())); - assertThat([NSPersistentStoreCoordinator defaultStoreCoordinator], is(notNilValue())); + assertThat([NSPersistentStoreCoordinator MR_defaultStoreCoordinator], is(notNilValue())); assertThat([NSPersistentStore defaultPersistentStore], is(notNilValue())); } @@ -90,7 +90,6 @@ assertThatBool(errorHandlerWasCalled_, is(equalToBool(YES))); } - - (void) testLogsErrorsToLogger { GHFail(@"Test Not Implemented"); diff --git a/iOS App Unit Tests/iOS App Unit Tests-Prefix.pch b/iOS App Unit Tests/iOS App Unit Tests-Prefix.pch index 016257f..631e4ef 100644 --- a/iOS App Unit Tests/iOS App Unit Tests-Prefix.pch +++ b/iOS App Unit Tests/iOS App Unit Tests-Prefix.pch @@ -17,6 +17,7 @@ #define HC_SHORTHAND #import + #define MR_SHORTHAND #import "CoreData+MagicalRecord.h" #import "FixtureHelpers.h" #endif