mirror of
https://github.com/zhigang1992/MagicalRecord.git
synced 2026-01-12 17:32:18 +08:00
Add helpers to specify persistent stores and model files at specific URLs, not auto configured ones
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
|
||||
+ (void) MR_setDefaultManagedObjectModel:(NSManagedObjectModel *)newDefaultModel;
|
||||
|
||||
+ (NSManagedObjectModel *) MR_managedObjectModelAtURL:(NSURL *)url;
|
||||
+ (NSManagedObjectModel *) MR_mergedObjectModelFromMainBundle;
|
||||
+ (NSManagedObjectModel *) MR_newManagedObjectModelNamed:(NSString *)modelFileName NS_RETURNS_RETAINED;
|
||||
+ (NSManagedObjectModel *) MR_managedObjectModelNamed:(NSString *)modelFileName;
|
||||
|
||||
@@ -27,6 +27,11 @@ static NSManagedObjectModel *defaultManagedObjectModel_ = nil;
|
||||
defaultManagedObjectModel_ = newDefaultModel;
|
||||
}
|
||||
|
||||
+ (NSManagedObjectModel *) MR_managedObjectModelAtURL:(NSURL *)url;
|
||||
{
|
||||
return [[NSManagedObjectModel alloc] initWithContentsOfURL:url];
|
||||
}
|
||||
|
||||
+ (NSManagedObjectModel *) MR_mergedObjectModelFromMainBundle;
|
||||
{
|
||||
return [self mergedModelFromBundles:nil];
|
||||
|
||||
@@ -22,12 +22,15 @@ extern NSString * const kMagicalRecordPSCDidCompleteiCloudSetupNotification;
|
||||
+ (NSPersistentStoreCoordinator *) MR_coordinatorWithSqliteStoreNamed:(NSString *)storeFileName;
|
||||
+ (NSPersistentStoreCoordinator *) MR_coordinatorWithAutoMigratingSqliteStoreNamed:(NSString *)storeFileName;
|
||||
+ (NSPersistentStoreCoordinator *) MR_coordinatorWithPersistentStore:(NSPersistentStore *)persistentStore;
|
||||
+ (NSPersistentStoreCoordinator *) MR_coordinatorWithSqliteStoreAtURL:(NSURL *)url;
|
||||
|
||||
+ (NSPersistentStoreCoordinator *) MR_coordinatorWithiCloudContainerID:(NSString *)containerID contentNameKey:(NSString *)contentNameKey localStoreNamed:(NSString *)localStoreName cloudStorePathComponent:(NSString *)subPathComponent;
|
||||
|
||||
+ (NSPersistentStoreCoordinator *) MR_coordinatorWithiCloudContainerID:(NSString *)containerID contentNameKey:(NSString *)contentNameKey localStoreNamed:(NSString *)localStoreName cloudStorePathComponent:(NSString *)subPathComponent completion:(void(^)(void))completionHandler;
|
||||
|
||||
- (NSPersistentStore *) MR_addInMemoryStore;
|
||||
- (NSPersistentStore *) MR_addAutoMigratingSqliteStoreNamed:(NSString *) storeFileName;
|
||||
- (NSPersistentStore *) MR_addSqliteStoreAtURL:(NSURL *)url withOptions:(NSDictionary *__autoreleasing)options;
|
||||
- (NSPersistentStore *) MR_addSqliteStoreNamed:(id)storeFileName withOptions:(__autoreleasing NSDictionary *)options;
|
||||
|
||||
- (void) MR_addiCloudContainerID:(NSString *)containerID contentNameKey:(NSString *)contentNameKey localStoreNamed:(NSString *)localStoreName cloudStorePathComponent:(NSString *)subPathComponent;
|
||||
|
||||
@@ -62,13 +62,17 @@ NSString * const kMagicalRecordPSCDidCompleteiCloudSetupNotification = @"kMagica
|
||||
}
|
||||
}
|
||||
|
||||
- (NSPersistentStore *) MR_addSqliteStoreNamed:(id)storeFileName withOptions:(__autoreleasing NSDictionary *)options
|
||||
|
||||
- (NSPersistentStore *) MR_addSqliteStoreNamed:(id)storeFileName withOptions:(__autoreleasing NSDictionary *)options;
|
||||
{
|
||||
NSURL *url = [storeFileName isKindOfClass:[NSURL class]] ? storeFileName : [NSPersistentStore MR_urlForStoreName:storeFileName];
|
||||
NSError *error = nil;
|
||||
|
||||
return [self MR_addSqliteStoreAtURL:url withOptions:options];
|
||||
}
|
||||
|
||||
- (NSPersistentStore *) MR_addSqliteStoreAtURL:(NSURL *)url withOptions:(NSDictionary *__autoreleasing)options;
|
||||
{
|
||||
[self MR_createPathToStoreFileIfNeccessary:url];
|
||||
|
||||
NSError *error = nil;
|
||||
NSPersistentStore *store = [self addPersistentStoreWithType:NSSQLiteStoreType
|
||||
configuration:nil
|
||||
URL:url
|
||||
@@ -264,7 +268,7 @@ NSString * const kMagicalRecordPSCDidCompleteiCloudSetupNotification = @"kMagica
|
||||
{
|
||||
NSManagedObjectModel *model = [NSManagedObjectModel MR_defaultManagedObjectModel];
|
||||
NSPersistentStoreCoordinator *psc = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:model];
|
||||
|
||||
|
||||
[psc MR_addSqliteStoreNamed:[persistentStore URL] withOptions:nil];
|
||||
|
||||
return psc;
|
||||
@@ -284,6 +288,14 @@ NSString * const kMagicalRecordPSCDidCompleteiCloudSetupNotification = @"kMagica
|
||||
return [self MR_coordinatorWithSqliteStoreNamed:storeFileName withOptions:nil];
|
||||
}
|
||||
|
||||
+ (NSPersistentStoreCoordinator *) MR_coordinatorWithSqliteStoreAtURL:(NSURL *)url;
|
||||
{
|
||||
NSManagedObjectModel *model = [NSManagedObjectModel MR_defaultManagedObjectModel];
|
||||
NSPersistentStoreCoordinator *psc = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:model];
|
||||
|
||||
[psc MR_addSqliteStoreAtURL:url withOptions:nil];
|
||||
return psc;
|
||||
}
|
||||
@end
|
||||
|
||||
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
+ (void) setupCoreDataStackWithInMemoryStore;
|
||||
+ (void) setupAutoMigratingCoreDataStack;
|
||||
|
||||
+ (void) setupCoreDataStackWithStoreAtURL:(NSURL *)url;
|
||||
|
||||
+ (void) setupCoreDataStackWithStoreNamed:(NSString *)storeName;
|
||||
+ (void) setupCoreDataStackWithAutoMigratingSqliteStoreNamed:(NSString *)storeName;
|
||||
|
||||
|
||||
@@ -53,4 +53,14 @@
|
||||
[NSManagedObjectContext MR_initializeDefaultContextWithCoordinator:coordinator];
|
||||
}
|
||||
|
||||
+ (void) setupCoreDataStackWithStoreAtURL:(NSURL *)url;
|
||||
{
|
||||
if ([NSPersistentStoreCoordinator MR_defaultStoreCoordinator] != nil) return;
|
||||
|
||||
NSPersistentStoreCoordinator *coordinator = [NSPersistentStoreCoordinator MR_coordinatorWithSqliteStoreAtURL:url];
|
||||
[NSPersistentStoreCoordinator MR_setDefaultStoreCoordinator:coordinator];
|
||||
|
||||
[NSManagedObjectContext MR_initializeDefaultContextWithCoordinator:coordinator];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user