Skip to content

Commit e90f76f

Browse files
committed
Improved formatting
1 parent 6617e8b commit e90f76f

5 files changed

Lines changed: 40 additions & 25 deletions

File tree

CoreDataMigration-Example.xcodeproj/project.pbxproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@
9090
43AB8AFC1F66E6A5003153B3 /* CoreDataMigration-ExampleTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "CoreDataMigration-ExampleTests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
9191
43AB8B021F66E6A5003153B3 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
9292
43EC64222F79925E0055607E /* CoreDataVersionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoreDataVersionTests.swift; sourceTree = "<group>"; };
93-
43FBB4421F6C16FB0090C536 /* CoreDataMigration-ExampleTests-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "CoreDataMigration-ExampleTests-Bridging-Header.h"; sourceTree = "<group>"; };
9493
/* End PBXFileReference section */
9594

9695
/* Begin PBXFrameworksBuildPhase section */
@@ -324,7 +323,6 @@
324323
434FE7382F795ACA00359208 /* Doubles */,
325324
434FE73F2F795ACA00359208 /* Resources */,
326325
434FE7432F795ACA00359208 /* Tests */,
327-
43FBB4421F6C16FB0090C536 /* CoreDataMigration-ExampleTests-Bridging-Header.h */,
328326
43AB8B021F66E6A5003153B3 /* Info.plist */,
329327
);
330328
path = "CoreDataMigration-ExampleTests";

CoreDataMigration-Example/CoreData/Migration/CoreDataMigrator.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class CoreDataMigrator: CoreDataMigrating {
3737
guard let metadata = NSPersistentStoreCoordinator.metadata(at: storeURL) else {
3838
return false
3939
}
40-
40+
4141
return !CoreDataMigrationModel.current.managedObjectModel().isConfiguration(withName: nil,
4242
compatibleWithStoreMetadata: metadata)
4343
}
@@ -55,9 +55,9 @@ class CoreDataMigrator: CoreDataMigrating {
5555
let sourceMigrationModel = CoreDataMigrationModel.migrationModelCompatibleWithStoreMetadata(metadata) else {
5656
fatalError("Unknown store version at URL \(sourceURL)")
5757
}
58-
58+
5959
forceWALCheckpointingForStore(at: sourceURL)
60-
60+
6161
var currentURL = sourceURL
6262
let migrationSteps = sourceMigrationModel.migrationSteps(to: targetVersion)
6363

@@ -97,10 +97,10 @@ class CoreDataMigrator: CoreDataMigrating {
9797
}
9898

9999
// MARK: - WAL
100-
100+
101101
private func forceWALCheckpointingForStore(at storeURL: URL) {
102102
guard let metadata = NSPersistentStoreCoordinator.metadata(at: storeURL),
103-
let migrationModel = CoreDataMigrationModel.migrationModelCompatibleWithStoreMetadata(metadata) else {
103+
let migrationModel = CoreDataMigrationModel.migrationModelCompatibleWithStoreMetadata(metadata) else {
104104
return
105105
}
106106

CoreDataMigration-Example/CoreData/Migration/Policies/Post2ToPost3MigrationPolicy.swift

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,26 @@ import CoreData
1010

1111
final class Post2ToPost3MigrationPolicy: NSEntityMigrationPolicy {
1212

13-
override func createDestinationInstances(forSource sInstance: NSManagedObject, in mapping: NSEntityMapping, manager: NSMigrationManager) throws {
14-
try super.createDestinationInstances(forSource: sInstance, in: mapping, manager: manager)
13+
override func createDestinationInstances(forSource sInstance: NSManagedObject,
14+
in mapping: NSEntityMapping,
15+
manager: NSMigrationManager) throws {
16+
try super.createDestinationInstances(forSource: sInstance,
17+
in: mapping,
18+
manager: manager)
1519

16-
guard let destinationPost = manager.destinationInstances(forEntityMappingName: mapping.name, sourceInstances: [sInstance]).first else {
20+
guard let destinationPost = manager.destinationInstances(forEntityMappingName: mapping.name,
21+
sourceInstances: [sInstance]).first else {
1722
fatalError("Expected a post")
1823
}
1924

20-
let color = NSEntityDescription.insertNewObject(forEntityName: "Color", into: destinationPost.managedObjectContext!)
21-
color.setValue(UUID().uuidString, forKey: "colorID")
22-
color.setValue(sInstance.value(forKey: "hexColor"), forKey: "hex")
25+
let color = NSEntityDescription.insertNewObject(forEntityName: "Color",
26+
into: destinationPost.managedObjectContext!)
27+
color.setValue(UUID().uuidString,
28+
forKey: "colorID")
29+
color.setValue(sInstance.value(forKey: "hexColor"),
30+
forKey: "hex")
2331

24-
destinationPost.setValue(color, forKey: "color")
32+
destinationPost.setValue(color,
33+
forKey: "color")
2534
}
2635
}

CoreDataMigration-Example/Extensions/NSPersistentStoreCoordinator/NSPersistentStoreCoordinator+SQLite.swift

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,25 @@ extension NSPersistentStoreCoordinator {
1515
static func destroyStore(at storeURL: URL) {
1616
do {
1717
let persistentStoreCoordinator = NSPersistentStoreCoordinator(managedObjectModel: NSManagedObjectModel())
18-
try persistentStoreCoordinator.destroyPersistentStore(at: storeURL, ofType: NSSQLiteStoreType, options: nil)
18+
try persistentStoreCoordinator.destroyPersistentStore(at: storeURL,
19+
ofType: NSSQLiteStoreType,
20+
options: nil)
1921
} catch let error {
2022
fatalError("Failed to destroy persistent store at \(storeURL), error: \(error)")
2123
}
2224
}
2325

2426
// MARK: - Replace
2527

26-
static func replaceStore(at targetURL: URL, withStoreAt sourceURL: URL) {
28+
static func replaceStore(at targetURL: URL,
29+
withStoreAt sourceURL: URL) {
2730
do {
2831
let persistentStoreCoordinator = NSPersistentStoreCoordinator(managedObjectModel: NSManagedObjectModel())
29-
try persistentStoreCoordinator.replacePersistentStore(at: targetURL, destinationOptions: nil, withPersistentStoreFrom: sourceURL, sourceOptions: nil, ofType: NSSQLiteStoreType)
32+
try persistentStoreCoordinator.replacePersistentStore(at: targetURL,
33+
destinationOptions: nil,
34+
withPersistentStoreFrom: sourceURL,
35+
sourceOptions: nil,
36+
ofType: NSSQLiteStoreType)
3037
} catch let error {
3138
fatalError("Failed to replace persistent store at \(targetURL) with \(sourceURL), error: \(error)")
3239
}
@@ -35,17 +42,22 @@ extension NSPersistentStoreCoordinator {
3542
// MARK: - Meta
3643

3744
static func metadata(at storeURL: URL) -> [String : Any]? {
38-
return try? NSPersistentStoreCoordinator.metadataForPersistentStore(ofType: NSSQLiteStoreType, at: storeURL, options: nil)
45+
return try? NSPersistentStoreCoordinator.metadataForPersistentStore(ofType: NSSQLiteStoreType,
46+
at: storeURL,
47+
options: nil)
3948
}
4049

4150
// MARK: - Add
4251

43-
func addPersistentStore(at storeURL: URL, options: [AnyHashable : Any]) -> NSPersistentStore {
52+
func addPersistentStore(at storeURL: URL,
53+
options: [AnyHashable : Any]) -> NSPersistentStore {
4454
do {
45-
return try addPersistentStore(ofType: NSSQLiteStoreType, configurationName: nil, at: storeURL, options: options)
55+
return try addPersistentStore(ofType: NSSQLiteStoreType,
56+
configurationName: nil,
57+
at: storeURL,
58+
options: options)
4659
} catch let error {
4760
fatalError("Failed to add persistent store to coordinator, error: \(error)")
4861
}
49-
5062
}
5163
}

CoreDataMigration-ExampleTests/CoreDataMigration-ExampleTests-Bridging-Header.h

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)