From 808e8ff97a7f5cf87735630c9c2a518ac699bf72 Mon Sep 17 00:00:00 2001 From: John Estropia Date: Thu, 9 Aug 2018 18:18:21 +0900 Subject: [PATCH] stabilize NSProgress when lightweight migration falls back to InferredMappingModel --- Sources/DataStack+Migration.swift | 4 ++-- Sources/MigrationManager.swift | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Sources/DataStack+Migration.swift b/Sources/DataStack+Migration.swift index e1a8be4..c6640dc 100644 --- a/Sources/DataStack+Migration.swift +++ b/Sources/DataStack+Migration.swift @@ -708,9 +708,9 @@ public extension DataStack { var fakeProgress: Float = 0 var recursiveCheck: () -> Void = {} - recursiveCheck = { + recursiveCheck = { [weak timerQueue] in - guard fakeProgress < 1 else { + guard let timerQueue = timerQueue, fakeProgress < 1 else { return } diff --git a/Sources/MigrationManager.swift b/Sources/MigrationManager.swift index eda35c8..042f66b 100644 --- a/Sources/MigrationManager.swift +++ b/Sources/MigrationManager.swift @@ -42,7 +42,10 @@ internal final class MigrationManager: NSMigrationManager, ProgressReporting { return } let progress = self.progress - progress.completedUnitCount = Int64(Float(progress.totalUnitCount) * self.migrationProgress) + progress.completedUnitCount = max( + progress.completedUnitCount, + Int64(Float(progress.totalUnitCount) * self.migrationProgress) + ) }