Compare commits

..

12 Commits
4.2.0 ... 4.2.4

Author SHA1 Message Date
John Rommel Estropia
18b933957e version bump 2017-11-16 02:28:18 +09:00
John Rommel Estropia
2c7039232e merge sqlite journal files before migration 2017-11-16 02:27:06 +09:00
John Rommel Estropia
d3b3b5ff4a added fake progress for lightweight migrations 2017-11-16 02:26:56 +09:00
John Rommel Estropia
d90e8d1303 force true lightweight migration 2017-11-16 02:26:44 +09:00
John Estropia
e314db8f56 version bump 2017-11-09 19:45:21 +09:00
John Estropia
48d936d068 Fix regression for ARC bugfix (fixes #221) 2017-11-09 19:44:27 +09:00
John Estropia
f3816b9abf update for Xcode 9.1 2017-11-01 19:49:42 +09:00
John Estropia
21961780d4 force dynamic typing on DynamicObject.Type to mitigate optimization issues 2017-11-01 19:38:38 +09:00
John Rommel Estropia
305e2b61a0 fix compile errors for Xcode 9.1 beta 2017-11-01 19:37:53 +09:00
John Estropia
588fa35c84 version bump 2017-10-17 13:39:57 +09:00
John Estropia
f6614cda66 Merge branch 'develop' 2017-10-17 13:39:20 +09:00
John Estropia
639574d8c2 remove inline casts because optimized builds seem to trip on them 2017-10-17 13:38:25 +09:00
13 changed files with 72 additions and 32 deletions

View File

@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "CoreStore"
s.version = "4.2.0"
s.version = "4.2.4"
s.license = "MIT"
s.summary = "Unleashing the real power of Core Data with the elegance and safety of Swift"
s.homepage = "https://github.com/JohnEstropia/CoreStore"

View File

@@ -560,7 +560,6 @@ extension ListMonitor where ListMonitor.ObjectType: NSManagedObject {
fileprivate func downcast() -> ListMonitor<NSManagedObject> {
@inline(__always)
func noWarnUnsafeBitCast<T, U>(_ x: T, to type: U.Type) -> U {
return unsafeBitCast(x, to: type)

View File

@@ -42,7 +42,7 @@ import CoreData
*/
@available(OSX 10.12, *)
@objc
public protocol CSListObserver: class, AnyObject {
public protocol CSListObserver: class {
/**
Handles processing just before a change to the observed list occurs

View File

@@ -152,7 +152,6 @@ extension ObjectMonitor where ObjectMonitor.ObjectType: NSManagedObject {
fileprivate func downcast() -> ObjectMonitor<NSManagedObject> {
@inline(__always)
func noWarnUnsafeBitCast<T, U>(_ x: T, to type: U.Type) -> U {
return unsafeBitCast(x, to: type)

View File

@@ -40,7 +40,7 @@ import CoreData
*/
@available(OSX 10.12, *)
@objc
public protocol CSObjectObserver: class, AnyObject {
public protocol CSObjectObserver: class {
/**
Handles processing just before a change to the observed `object` occurs

View File

@@ -33,7 +33,7 @@ import CoreData
Objective-C Foundation types that are natively supported by Core Data managed attributes all conform to `CoreDataNativeType`.
*/
@objc
public protocol CoreDataNativeType: class, NSObjectProtocol, AnyObject {}
public protocol CoreDataNativeType: class, NSObjectProtocol {}
// MARK: - NSNumber

View File

@@ -235,9 +235,8 @@ CSWhere *_Nonnull CSWherePredicate(NSPredicate *_Nonnull predicate) CORESTORE_RE
- (void)setAffectedStores:(NSArray<NSPersistentStore *> *_Nullable)affectedStores {
NSProcessInfo *processInfo = [NSProcessInfo processInfo];
if ([processInfo isOperatingSystemAtLeastVersion:(NSOperatingSystemVersion){ 11, 0, 0 }]
|| ![processInfo isOperatingSystemAtLeastVersion:(NSOperatingSystemVersion){ 10, 0, 0 }]) {
if (NSFoundationVersionNumber < NSFoundationVersionNumber10_0
|| [[NSProcessInfo processInfo] isOperatingSystemAtLeastVersion:(NSOperatingSystemVersion){ 11, 0, 0 }]) {
self.safeAffectedStores = affectedStores;
[super setAffectedStores:affectedStores];

View File

@@ -31,7 +31,7 @@ import Foundation
/**
`CoreStoreObjectiveCType`s are Objective-C accessible classes that represent CoreStore's Swift types.
*/
public protocol CoreStoreObjectiveCType: class, AnyObject {
public protocol CoreStoreObjectiveCType: class {
/**
The corresponding Swift type

View File

@@ -575,6 +575,7 @@ public extension DataStack {
sourceModel: sourceModel,
destinationModel: destinationModel,
mappingModel: mappingModel,
migrationType: migrationType,
progress: childProgress
)
}
@@ -679,10 +680,66 @@ public extension DataStack {
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
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)
.appendingPathComponent(Bundle.main.bundleIdentifier ?? "com.CoreStore.DataStack")
.appendingPathComponent(ProcessInfo().globallyUniqueString)

View File

@@ -121,8 +121,7 @@ extension CoreStoreObject {
return unsafeDowncast(coreStoreObject, to: self)
}
@inline(__always)
func forceTypeCast<T: CoreStoreObject>(_ type: DynamicObject.Type, to: T.Type) -> T.Type {
func forceTypeCast<T: CoreStoreObject>(_ type: AnyClass, to: T.Type) -> T.Type {
return type as! T.Type
}

View File

@@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>4.2.0</string>
<string>4.2.4</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>

View File

@@ -72,15 +72,13 @@ internal extension NSPersistentStoreCoordinator {
}
@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?
var storeError: NSError?
self.performSynchronously {
return try self.performSynchronously {
do {
store = try self.addPersistentStore(
return try self.addPersistentStore(
ofType: storeType,
configurationName: configuration,
at: storeURL,
@@ -89,13 +87,8 @@ internal extension NSPersistentStoreCoordinator {
}
catch {
storeError = error as NSError
throw CoreStoreError(error)
}
}
if let store = store {
return store
}
throw CoreStoreError(storeError)
}
}

View File

@@ -350,7 +350,6 @@ extension NSData: QueryableAttributeType {
@nonobjc @inline(__always)
public class func cs_fromQueryableNativeType(_ value: QueryableNativeType) -> Self? {
@inline(__always)
func forceCast<T: NSData>(_ value: Any) -> T? {
return value as? T
@@ -380,7 +379,6 @@ extension NSDate: QueryableAttributeType {
@nonobjc @inline(__always)
public class func cs_fromQueryableNativeType(_ value: QueryableNativeType) -> Self? {
@inline(__always)
func forceCast<T: NSDate>(_ value: Any) -> T? {
return value as? T
@@ -421,7 +419,6 @@ extension NSManagedObjectID: QueryableAttributeType {
@nonobjc @inline(__always)
public class func cs_fromQueryableNativeType(_ value: QueryableNativeType) -> Self? {
@inline(__always)
func forceCast<T: NSManagedObjectID>(_ value: Any) -> T? {
return value as? T
@@ -451,7 +448,6 @@ extension NSNull: QueryableAttributeType {
@nonobjc @inline(__always)
public class func cs_fromQueryableNativeType(_ value: QueryableNativeType) -> Self? {
@inline(__always)
func forceCast<T: NSNull>(_ value: Any) -> T? {
return value as? T
@@ -481,7 +477,6 @@ extension NSNumber: QueryableAttributeType {
@nonobjc @inline(__always)
public class func cs_fromQueryableNativeType(_ value: QueryableNativeType) -> Self? {
@inline(__always)
func forceCast<T: NSNumber>(_ value: Any) -> T? {
return value as? T
@@ -511,7 +506,6 @@ extension NSString: QueryableAttributeType {
@nonobjc @inline(__always)
public class func cs_fromQueryableNativeType(_ value: QueryableNativeType) -> Self? {
@inline(__always)
func forceCast<T: NSString>(_ value: Any) -> T? {
return value as? T