mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-01-15 05:33:31 +01:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
18b933957e | ||
|
|
2c7039232e | ||
|
|
d3b3b5ff4a | ||
|
|
d90e8d1303 | ||
|
|
e314db8f56 | ||
|
|
48d936d068 |
@@ -1,6 +1,6 @@
|
|||||||
Pod::Spec.new do |s|
|
Pod::Spec.new do |s|
|
||||||
s.name = "CoreStore"
|
s.name = "CoreStore"
|
||||||
s.version = "4.2.2"
|
s.version = "4.2.4"
|
||||||
s.license = "MIT"
|
s.license = "MIT"
|
||||||
s.summary = "Unleashing the real power of Core Data with the elegance and safety of Swift"
|
s.summary = "Unleashing the real power of Core Data with the elegance and safety of Swift"
|
||||||
s.homepage = "https://github.com/JohnEstropia/CoreStore"
|
s.homepage = "https://github.com/JohnEstropia/CoreStore"
|
||||||
|
|||||||
@@ -235,9 +235,8 @@ CSWhere *_Nonnull CSWherePredicate(NSPredicate *_Nonnull predicate) CORESTORE_RE
|
|||||||
|
|
||||||
- (void)setAffectedStores:(NSArray<NSPersistentStore *> *_Nullable)affectedStores {
|
- (void)setAffectedStores:(NSArray<NSPersistentStore *> *_Nullable)affectedStores {
|
||||||
|
|
||||||
NSProcessInfo *processInfo = [NSProcessInfo processInfo];
|
if (NSFoundationVersionNumber < NSFoundationVersionNumber10_0
|
||||||
if ([processInfo isOperatingSystemAtLeastVersion:(NSOperatingSystemVersion){ 11, 0, 0 }]
|
|| [[NSProcessInfo processInfo] isOperatingSystemAtLeastVersion:(NSOperatingSystemVersion){ 11, 0, 0 }]) {
|
||||||
|| ![processInfo isOperatingSystemAtLeastVersion:(NSOperatingSystemVersion){ 10, 0, 0 }]) {
|
|
||||||
|
|
||||||
self.safeAffectedStores = affectedStores;
|
self.safeAffectedStores = affectedStores;
|
||||||
[super setAffectedStores:affectedStores];
|
[super setAffectedStores:affectedStores];
|
||||||
|
|||||||
@@ -575,6 +575,7 @@ public extension DataStack {
|
|||||||
sourceModel: sourceModel,
|
sourceModel: sourceModel,
|
||||||
destinationModel: destinationModel,
|
destinationModel: destinationModel,
|
||||||
mappingModel: mappingModel,
|
mappingModel: mappingModel,
|
||||||
|
migrationType: migrationType,
|
||||||
progress: childProgress
|
progress: childProgress
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -679,10 +680,66 @@ public extension DataStack {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
private func startMigrationForStorage<T: LocalStorage>(_ storage: T, sourceModel: NSManagedObjectModel, destinationModel: NSManagedObjectModel, mappingModel: NSMappingModel, progress: Progress) throws {
|
private func startMigrationForStorage<T: LocalStorage>(_ storage: T, sourceModel: NSManagedObjectModel, destinationModel: NSManagedObjectModel, mappingModel: NSMappingModel, migrationType: MigrationType, progress: Progress) throws {
|
||||||
|
|
||||||
let fileURL = storage.fileURL
|
let fileURL = storage.fileURL
|
||||||
|
if case .lightweight = migrationType {
|
||||||
|
|
||||||
|
do {
|
||||||
|
|
||||||
|
let timerQueue = DispatchQueue(
|
||||||
|
label: "DataStack.lightweightMigration.timerQueue",
|
||||||
|
qos: .utility,
|
||||||
|
attributes: []
|
||||||
|
)
|
||||||
|
let estimatedTime: TimeInterval = 60 * 3 // 3 mins
|
||||||
|
let interval: TimeInterval = 1
|
||||||
|
let fakeTotalUnitCount: Float = 0.9 * Float(progress.totalUnitCount)
|
||||||
|
var fakeProgress: Float = 0
|
||||||
|
|
||||||
|
var recursiveCheck: () -> Void = {}
|
||||||
|
recursiveCheck = {
|
||||||
|
|
||||||
|
guard fakeProgress < 1 else {
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
progress.completedUnitCount = Int64(fakeTotalUnitCount * fakeProgress)
|
||||||
|
fakeProgress += Float(interval / estimatedTime)
|
||||||
|
|
||||||
|
timerQueue.asyncAfter(
|
||||||
|
deadline: .now() + interval,
|
||||||
|
execute: recursiveCheck
|
||||||
|
)
|
||||||
|
}
|
||||||
|
timerQueue.async(execute: recursiveCheck)
|
||||||
|
|
||||||
|
_ = try storage.cs_finalizeStorageAndWait(soureModelHint: sourceModel)
|
||||||
|
_ = try withExtendedLifetime(NSPersistentStoreCoordinator(managedObjectModel: destinationModel)) { (coordinator: NSPersistentStoreCoordinator) in
|
||||||
|
|
||||||
|
try coordinator.addPersistentStoreSynchronously(
|
||||||
|
type(of: storage).storeType,
|
||||||
|
configuration: storage.configuration,
|
||||||
|
URL: fileURL,
|
||||||
|
options: storage.dictionary(
|
||||||
|
forOptions: storage.localStorageOptions.union(.allowSynchronousLightweightMigration)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
timerQueue.sync {
|
||||||
|
|
||||||
|
fakeProgress = 1
|
||||||
|
}
|
||||||
|
_ = try? storage.cs_finalizeStorageAndWait(soureModelHint: destinationModel)
|
||||||
|
progress.completedUnitCount = progress.totalUnitCount
|
||||||
|
return
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
|
||||||
|
// try manual migration
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let temporaryDirectoryURL = URL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true)
|
let temporaryDirectoryURL = URL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true)
|
||||||
.appendingPathComponent(Bundle.main.bundleIdentifier ?? "com.CoreStore.DataStack")
|
.appendingPathComponent(Bundle.main.bundleIdentifier ?? "com.CoreStore.DataStack")
|
||||||
.appendingPathComponent(ProcessInfo().globallyUniqueString)
|
.appendingPathComponent(ProcessInfo().globallyUniqueString)
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
<key>CFBundlePackageType</key>
|
<key>CFBundlePackageType</key>
|
||||||
<string>FMWK</string>
|
<string>FMWK</string>
|
||||||
<key>CFBundleShortVersionString</key>
|
<key>CFBundleShortVersionString</key>
|
||||||
<string>4.2.2</string>
|
<string>4.2.4</string>
|
||||||
<key>CFBundleSignature</key>
|
<key>CFBundleSignature</key>
|
||||||
<string>????</string>
|
<string>????</string>
|
||||||
<key>CFBundleVersion</key>
|
<key>CFBundleVersion</key>
|
||||||
|
|||||||
@@ -72,15 +72,13 @@ internal extension NSPersistentStoreCoordinator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
internal func addPersistentStoreSynchronously(_ storeType: String, configuration: ModelConfiguration, URL storeURL: URL?, options: [NSObject : AnyObject]?) throws -> NSPersistentStore {
|
internal func addPersistentStoreSynchronously(_ storeType: String, configuration: ModelConfiguration, URL storeURL: URL?, options: [AnyHashable: Any]?) throws -> NSPersistentStore {
|
||||||
|
|
||||||
var store: NSPersistentStore?
|
return try self.performSynchronously {
|
||||||
var storeError: NSError?
|
|
||||||
self.performSynchronously {
|
|
||||||
|
|
||||||
do {
|
do {
|
||||||
|
|
||||||
store = try self.addPersistentStore(
|
return try self.addPersistentStore(
|
||||||
ofType: storeType,
|
ofType: storeType,
|
||||||
configurationName: configuration,
|
configurationName: configuration,
|
||||||
at: storeURL,
|
at: storeURL,
|
||||||
@@ -89,13 +87,8 @@ internal extension NSPersistentStoreCoordinator {
|
|||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
|
|
||||||
storeError = error as NSError
|
throw CoreStoreError(error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let store = store {
|
|
||||||
|
|
||||||
return store
|
|
||||||
}
|
|
||||||
throw CoreStoreError(storeError)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user