Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'master' of https://github.com/magicalpanda/MagicalRecord

  • Loading branch information...
commit 466530c8d1d62a9a0386a7f6a8abb9a0538637a9 2 parents 49e51b7 + fe59756
Duane Fields duanefields authored
7 README.md
View
@@ -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:
2  Source/Categories/NSManagedObject+MagicalRecord.m
View
@@ -113,7 +113,7 @@ + (NSArray *) MR_propertiesNamed:(NSArray *)properties
}
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));
}
}
}
15 Source/CoreData+MagicalRecord.h
View
@@ -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)
1  Source/MagicalRecordHelpers.h
View
@@ -29,6 +29,7 @@ typedef void (^CoreDataBlock)(NSManagedObjectContext *context);
+ (SEL) errorHandlerAction;
+ (id) errorHandlerTarget;
++ (void) setDefaultModelForTestCase:(Class)class;
+ (void) setDefaultModelNamed:(NSString *)modelName;
+ (NSString *) defaultStoreName;
8 Source/MagicalRecordHelpers.m
View
@@ -75,6 +75,7 @@ + (void) defaultErrorHandler:(NSError *)error
MRLog(@"Error: %@", detailedError);
}
}
+ MRLog(@"Error Message: %@", [error localizedDescription]);
MRLog(@"Error Domain: %@", [error domain]);
MRLog(@"Recovery Suggestion: %@", [error localizedRecoverySuggestion]);
}
@@ -126,6 +127,13 @@ + (void) setDefaultModelNamed:(NSString *)modelName;
[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];
4 Source/MagicalRecordShorthand.h
View
@@ -96,6 +96,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<NSFetchedResultsControllerDelegate>)delegate;
+ (NSFetchedResultsController *) fetchAllSortedBy:(NSString *)sortTerm ascending:(BOOL)ascending withPredicate:(NSPredicate *)searchTerm groupBy:(NSString *)groupingKeyPath delegate:(id<NSFetchedResultsControllerDelegate>)delegate inContext:(NSManagedObjectContext *)context;
@@ -103,6 +105,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<NSFetchedResultsControllerDelegate>)delegate;
+ (NSFetchedResultsController *) fetchAllGroupedBy:(NSString *)group withPredicate:(NSPredicate *)searchTerm sortedBy:(NSString *)sortTerm ascending:(BOOL)ascending delegate:(id<NSFetchedResultsControllerDelegate>)delegate inContext:(NSManagedObjectContext *)context;
+#endif
+
@end
@interface NSManagedObjectContext (MagicalRecordShortHand)
- (void) observeContext:(NSManagedObjectContext *)otherContext;
Please sign in to comment.
Something went wrong with that request. Please try again.