From fb267342f798365181f7bc4bf5972cf8770a78f9 Mon Sep 17 00:00:00 2001 From: Tomasz Czyzak Date: Wed, 26 Jul 2017 10:07:57 +0200 Subject: [PATCH] #278 migration support for database delivered in framework --- Incremental Store/EncryptedStore.h | 2 ++ Incremental Store/EncryptedStore.m | 22 ++++++++++++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/Incremental Store/EncryptedStore.h b/Incremental Store/EncryptedStore.h index 81ec5a8..e94854f 100755 --- a/Incremental Store/EncryptedStore.h +++ b/Incremental Store/EncryptedStore.h @@ -20,6 +20,8 @@ extern NSString * const EncryptedStoreErrorMessageKey; extern NSString * const EncryptedStoreDatabaseLocation; extern NSString * const EncryptedStoreCacheSize; extern NSString * const EncryptedStoreFileManagerOption; +extern NSString * const EncryptedStoreBundleId; + typedef NS_ENUM(NSInteger, EncryptedStoreError) { EncryptedStoreErrorIncorrectPasscode = 6000, diff --git a/Incremental Store/EncryptedStore.m b/Incremental Store/EncryptedStore.m index b2773ea..986b5f1 100755 --- a/Incremental Store/EncryptedStore.m +++ b/Incremental Store/EncryptedStore.m @@ -22,6 +22,7 @@ NSString * const EncryptedStoreDatabaseLocation = @"EncryptedStoreDatabaseLocation"; NSString * const EncryptedStoreCacheSize = @"EncryptedStoreCacheSize"; NSString * const EncryptedStoreFileManagerOption = @"EncryptedStoreFileManagerOption"; +NSString * const EncryptedStoreBundleId = @"EncryptedStoreBundleId"; static void dbsqliteRegExp(sqlite3_context *context, int argc, const char **argv); static void dbsqliteStripCase(sqlite3_context *context, int argc, const char **argv); @@ -965,12 +966,21 @@ - (BOOL)loadMetadata:(NSError **)error { if ([newModel isConfiguration:nil compatibleWithStoreMetadata:metadata]){ return YES; } - - // load the old model: - NSMutableArray *bundles = [NSMutableArray array]; - NSBundle *bundle = self.fileManager.configuration.bundle; - [bundles addObject:bundle]; - NSManagedObjectModel *oldModel = [NSManagedObjectModel mergedModelFromBundles:bundles + + // load the old model + NSBundle *modelBundle; + NSString *bundleId = [options objectForKey:EncryptedStoreBundleId]; + if (bundleId.length > 0) + { + modelBundle = [NSBundle bundleWithIdentifier:bundleId]; + } + + if (modelBundle == nil) + { + modelBundle = [NSBundle mainBundle]; + } + + NSManagedObjectModel *oldModel = [NSManagedObjectModel mergedModelFromBundles:@[modelBundle] forStoreMetadata:metadata]; if (oldModel && newModel) {