Skip to content

Commit

Permalink
Support for Core Data changes on iOS 11
Browse files Browse the repository at this point in the history
Workaround for binary store changes on iOS 11. A better way to do this
should be using NSBinaryStoreSecureDecodingClasses option in the future.
  • Loading branch information
keremerkan committed Sep 10, 2017
1 parent 83cc4ae commit e7db197
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
13 changes: 10 additions & 3 deletions Framework/Source/Events/CDEEventMigrator.m
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,17 @@ - (void)migrateEventsInFromFiles:(NSArray *)paths completion:(CDECompletionBlock
NSDictionary *metadata = [NSPersistentStoreCoordinator metadataForPersistentStoreOfType:nil URL:fileURL error:&error];
NSString *storeType = metadata[NSStoreTypeKey];
if (!storeType) @throw [[NSException alloc] initWithName:CDEException reason:@"" userInfo:nil];

#warning Using hard coded string here to get around problems in Xcode 9 Beta. Replace this with constant in final release
NSDictionary *options = @{NSMigratePersistentStoresAutomaticallyOption: @YES, NSInferMappingModelAutomaticallyOption: @YES, @"_NSBinaryStoreInsecureDecodingCompatibilityOption": @YES};

NSDictionary *options = nil;
if (@available(iOS 11.0, *)) {
options = @{NSMigratePersistentStoresAutomaticallyOption: @YES, NSInferMappingModelAutomaticallyOption: @YES, NSBinaryStoreInsecureDecodingCompatibilityOption: @YES};
} else {
// Fallback on earlier versions
options = @{NSMigratePersistentStoresAutomaticallyOption: @YES, NSInferMappingModelAutomaticallyOption: @YES};
}

fileStore = [importContext.persistentStoreCoordinator addPersistentStoreWithType:storeType configuration:nil URL:fileURL options:options error:&error];

if (!fileStore) @throw [[NSException alloc] initWithName:CDEException reason:@"" userInfo:nil];

BOOL success = [self migrateObjectsInContext:importContext toContext:self.eventStore.managedObjectContext error:&error];
Expand Down
7 changes: 6 additions & 1 deletion Framework/Tests/CDEBaseliningSyncTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,12 @@ - (NSManagedObjectContext *)eventFileContextForURL:(NSURL *)baselineURL
NSManagedObjectModel *eventModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];
NSPersistentStoreCoordinator *coordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:eventModel];
baselineContext.persistentStoreCoordinator = coordinator;
NSDictionary *options = @{@"_NSBinaryStoreInsecureDecodingCompatibilityOption": @YES};
NSDictionary *options = nil;

if (@available(iOS 11.0, *)) {
options = @{NSBinaryStoreInsecureDecodingCompatibilityOption: @YES};
}

NSPersistentStore *store = [coordinator addPersistentStoreWithType:NSBinaryStoreType configuration:nil URL:baselineURL options:options error:NULL];
XCTAssertNotNil(store, @"Store was nil");
return baselineContext;
Expand Down
7 changes: 6 additions & 1 deletion Framework/Tests/CDEEventMigratorTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,12 @@ - (NSManagedObjectContext *)makeFileContext
NSURL *url = [NSURL fileURLWithPath:exportedEventsFile];
NSManagedObjectModel *model = self.eventStore.managedObjectContext.persistentStoreCoordinator.managedObjectModel;
NSPersistentStoreCoordinator *psc = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:model];
NSDictionary *options = @{@"_NSBinaryStoreInsecureDecodingCompatibilityOption" : @YES};
NSDictionary *options = nil;

if (@available(iOS 11.0, *)) {
options = @{NSBinaryStoreInsecureDecodingCompatibilityOption: @YES};
}

[psc addPersistentStoreWithType:NSBinaryStoreType configuration:nil URL:url options:options error:NULL];
NSManagedObjectContext *newContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType];
newContext.persistentStoreCoordinator = psc;
Expand Down

0 comments on commit e7db197

Please sign in to comment.