From 2209c3e3a7a9d0d43cb33fa70844c5fbe32302e2 Mon Sep 17 00:00:00 2001 From: Saul Mora Date: Wed, 28 Dec 2011 19:26:53 -0700 Subject: [PATCH 1/5] Added support for easy setup with OCTest --- Source/MagicalRecordHelpers.h | 1 + Source/MagicalRecordHelpers.m | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/Source/MagicalRecordHelpers.h b/Source/MagicalRecordHelpers.h index ed1de9d..8e41d0e 100644 --- a/Source/MagicalRecordHelpers.h +++ b/Source/MagicalRecordHelpers.h @@ -29,6 +29,7 @@ typedef void (^CoreDataBlock)(NSManagedObjectContext *context); + (SEL) errorHandlerAction; + (id) errorHandlerTarget; ++ (void) setDefaultModelForTestCase:(Class)class; + (void) setDefaultModelNamed:(NSString *)modelName; + (NSString *) defaultStoreName; diff --git a/Source/MagicalRecordHelpers.m b/Source/MagicalRecordHelpers.m index 5a7ba7b..a286ae0 100644 --- a/Source/MagicalRecordHelpers.m +++ b/Source/MagicalRecordHelpers.m @@ -75,6 +75,7 @@ void replaceSelectorForTargetWithSourceImpAndSwizzle(Class originalClass, SEL or MRLog(@"Error: %@", detailedError); } } + MRLog(@"Error Message: %@", [error localizedDescription]); MRLog(@"Error Domain: %@", [error domain]); MRLog(@"Recovery Suggestion: %@", [error localizedRecoverySuggestion]); } @@ -126,6 +127,13 @@ void replaceSelectorForTargetWithSourceImpAndSwizzle(Class originalClass, SEL or [NSManagedObjectModel MR_setDefaultManagedObjectModel:model]; } ++ (void) setDefaultModelForTestCase:(Class)class; +{ + NSBundle *bundle = [NSBundle bundleForClass:class]; + NSManagedObjectModel *model = [NSManagedObjectModel mergedModelFromBundles:[NSArray arrayWithObject:bundle]]; + [NSManagedObjectModel MR_setDefaultManagedObjectModel:model]; +} + + (NSString *) defaultStoreName; { NSString *defaultName = [[[NSBundle mainBundle] infoDictionary] valueForKey:(id)kCFBundleNameKey]; From 121020a2c9802015927c12bff0f717e10fb24bef Mon Sep 17 00:00:00 2001 From: rickerbh Date: Thu, 29 Dec 2011 15:03:45 +1100 Subject: [PATCH 2/5] Modified macro to avoid "Can only use -performBlock" error --- Source/CoreData+MagicalRecord.h | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/Source/CoreData+MagicalRecord.h b/Source/CoreData+MagicalRecord.h index 2f521aa..b40af80 100644 --- a/Source/CoreData+MagicalRecord.h +++ b/Source/CoreData+MagicalRecord.h @@ -32,18 +32,29 @@ #define kCFCoreFoundationVersionNumber_iPhoneOS_5_0 674.0 #endif +#ifndef kCFCoreFoundationVersionNumber_10_7 +#define kCFCoreFoundationVersionNumber_10_7 635.0 +#endif + +#if TARGET_OS_IPHONE == 0 +#define MR_MINIMUM_PRIVATE_QUEUE_CF_VERSION kCFCoreFoundationVersionNumber_10_7 +#else +#define MR_MINIMUM_PRIVATE_QUEUE_CF_VERSION kCFCoreFoundationVersionNumber_iPhoneOS_5_0 +#endif + #define PRIVATE_QUEUES_ENABLED(...) \ - if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber_iPhoneOS_5_0) \ + if (kCFCoreFoundationVersionNumber >= MR_MINIMUM_PRIVATE_QUEUE_CF_VERSION) \ { \ __VA_ARGS__ \ } #define THREAD_ISOLATION_ENABLED(...) \ - if (kCFCoreFoundationVersionNumber < kCFCoreFoundationVersionNumber_iPhoneOS_5_0) \ + if (kCFCoreFoundationVersionNumber < MR_MINIMUM_PRIVATE_QUEUE_CF_VERSION) \ { \ __VA_ARGS__ \ } + #if MR_USE_ARC #define MR_RETAIN(xx) #define MR_RELEASE(xx) From 5452a2946fce52da05ce9f8e5adb45ea3c6f7dc1 Mon Sep 17 00:00:00 2001 From: Tony Xiao Date: Wed, 28 Dec 2011 23:10:19 -0500 Subject: [PATCH 3/5] Added in test for iOS target in MagicalRecordShorthand.h to make it compile on Mac-only targets --- Source/MagicalRecordShorthand.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Source/MagicalRecordShorthand.h b/Source/MagicalRecordShorthand.h index be4d454..32197cc 100644 --- a/Source/MagicalRecordShorthand.h +++ b/Source/MagicalRecordShorthand.h @@ -92,6 +92,8 @@ + (NSNumber *)aggregateOperation:(NSString *)function onAttribute:(NSString *)attributeName withPredicate:(NSPredicate *)predicate; - (id) inContext:(NSManagedObjectContext *)otherContext; - (id) inThreadContext; + +#if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR + (void) performFetch:(NSFetchedResultsController *)controller; + (NSFetchedResultsController *) fetchAllSortedBy:(NSString *)sortTerm ascending:(BOOL)ascending withPredicate:(NSPredicate *)searchTerm groupBy:(NSString *)groupingKeyPath delegate:(id)delegate; + (NSFetchedResultsController *) fetchAllSortedBy:(NSString *)sortTerm ascending:(BOOL)ascending withPredicate:(NSPredicate *)searchTerm groupBy:(NSString *)groupingKeyPath delegate:(id)delegate inContext:(NSManagedObjectContext *)context; @@ -99,6 +101,8 @@ + (NSFetchedResultsController *) fetchAllGroupedBy:(NSString *)group withPredicate:(NSPredicate *)searchTerm sortedBy:(NSString *)sortTerm ascending:(BOOL)ascending inContext:(NSManagedObjectContext *)context; + (NSFetchedResultsController *) fetchAllGroupedBy:(NSString *)group withPredicate:(NSPredicate *)searchTerm sortedBy:(NSString *)sortTerm ascending:(BOOL)ascending delegate:(id)delegate; + (NSFetchedResultsController *) fetchAllGroupedBy:(NSString *)group withPredicate:(NSPredicate *)searchTerm sortedBy:(NSString *)sortTerm ascending:(BOOL)ascending delegate:(id)delegate inContext:(NSManagedObjectContext *)context; +#endif + @end @interface NSManagedObjectContext (MagicalRecordShortHand) - (void) observeContext:(NSManagedObjectContext *)otherContext; From feffba86e7ee591436a9d7ec4d718ccc73bca626 Mon Sep 17 00:00:00 2001 From: tonyxiao Date: Wed, 28 Dec 2011 23:19:53 -0500 Subject: [PATCH 4/5] Update Readme.md to reflect recent changes, especially the MR_SHORTHAND macro --- README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ee782cf..47fc570 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,8 @@ Magical Record for Core Data was inspired by the ease of Ruby on Rails' Active R 1. In your XCode Project, add all the .h and .m files from the *Source* folder into your project. 2. Add *CoreData+MagicalRecord.h* file to your PCH file or your AppDelegate file. -3. Start writing code! ... There is no step 3! + * Optionally add `#define MR_SHORTHAND` to your PCH file if you want to use shorthand like `findAll` instead of `MR_findAll` +4. Start writing code! ... There is no step 3! # ARC Support @@ -71,9 +72,11 @@ Magical Record also has a helper method to hold on to a Managed Object Context i Most methods in MagicalRecord return an NSArray of results. So, if you have an Entity called Person, related to a Department (as seen in various Apple Core Data documentation), to get all the Person entities from your Persistent Store: - + //In order for this to work you need to add "#define MR_SHORTHAND" to your PCH file NSArray *people = [Person findAll]; + // Otherwise you can use the longer, namespaced version + NSArray *people = [Person MR_findAll]; Or, to have the results sorted by a property: From 6756aef88613ef5fd2cc228af7caf502f5b49480 Mon Sep 17 00:00:00 2001 From: Vojto Rinik Date: Thu, 29 Dec 2011 18:09:55 +0100 Subject: [PATCH 5/5] Fixing an issue that would cause EXC_BAD_ACCESS when property is not found. --- Source/Categories/NSManagedObject+MagicalRecord.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Categories/NSManagedObject+MagicalRecord.m b/Source/Categories/NSManagedObject+MagicalRecord.m index 77cbe90..aca7f8d 100644 --- a/Source/Categories/NSManagedObject+MagicalRecord.m +++ b/Source/Categories/NSManagedObject+MagicalRecord.m @@ -113,7 +113,7 @@ static NSUInteger defaultBatchSize = kMagicalRecordDefaultBatchSize; } else { - MRLog(@"Property '%@' not found in %@ properties for %@", propertyName, [propDict count], NSStringFromClass(self)); + MRLog(@"Property '%@' not found in %d properties for %@", propertyName, [propDict count], NSStringFromClass(self)); } } }