mirror of
https://github.com/zhigang1992/MagicalRecord.git
synced 2026-01-12 17:32:18 +08:00
Merge branch 'master' of magicalpanda.github.com:magicalpanda/MagicalRecord
This commit is contained in:
@@ -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:
|
||||
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -29,6 +29,7 @@ typedef void (^CoreDataBlock)(NSManagedObjectContext *context);
|
||||
+ (SEL) errorHandlerAction;
|
||||
+ (id) errorHandlerTarget;
|
||||
|
||||
+ (void) setDefaultModelForTestCase:(Class)class;
|
||||
+ (void) setDefaultModelNamed:(NSString *)modelName;
|
||||
+ (NSString *) defaultStoreName;
|
||||
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -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<NSFetchedResultsControllerDelegate>)delegate;
|
||||
+ (NSFetchedResultsController *) fetchAllSortedBy:(NSString *)sortTerm ascending:(BOOL)ascending withPredicate:(NSPredicate *)searchTerm groupBy:(NSString *)groupingKeyPath delegate:(id<NSFetchedResultsControllerDelegate>)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<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;
|
||||
|
||||
Reference in New Issue
Block a user