From bdf6308d8fa236c1d0b97f590fa6c9e0c42badeb Mon Sep 17 00:00:00 2001 From: John Estropia Date: Tue, 7 Feb 2017 18:17:40 +0900 Subject: [PATCH] swift 3.1 support --- .../Concrete Clauses/From.swift | 2 +- Sources/Importing/CoreDataNativeType.swift | 12 ++++++------ Sources/Internal/NSManagedObjectModel+Setup.swift | 2 +- .../ObjectiveC/CSAsynchronousDataTransaction.swift | 5 ++++- Sources/ObjectiveC/CSBaseDataTransaction.swift | 10 ---------- Sources/ObjectiveC/CSDataStack.swift | 5 ++++- Sources/ObjectiveC/CSFrom.swift | 2 +- Sources/ObjectiveC/CSGroupBy.swift | 5 ++++- Sources/ObjectiveC/CSInMemoryStore.swift | 5 ++++- Sources/ObjectiveC/CSInto.swift | 2 +- Sources/ObjectiveC/CSListMonitor.swift | 2 +- Sources/ObjectiveC/CSMigrationResult.swift | 5 ++++- Sources/ObjectiveC/CSMigrationType.swift | 5 ++++- Sources/ObjectiveC/CSObjectMonitor.swift | 2 +- Sources/ObjectiveC/CSOrderBy.swift | 5 ++++- Sources/ObjectiveC/CSSQliteStore.swift | 5 ++++- Sources/ObjectiveC/CSSaveResult.swift | 5 ++++- Sources/ObjectiveC/CSSectionBy.swift | 5 ++++- Sources/ObjectiveC/CSSelect.swift | 5 ++++- Sources/ObjectiveC/CSSetupResult.swift | 2 -- .../ObjectiveC/CSSynchronousDataTransaction.swift | 5 ++++- Sources/ObjectiveC/CSTweak.swift | 5 ++++- Sources/ObjectiveC/CSUnsafeDataTransaction.swift | 5 ++++- Sources/ObjectiveC/CSWhere.swift | 5 ++++- Sources/ObjectiveC/CoreStoreBridge.swift | 14 +++----------- .../NSFetchedResultsController+ObjectiveC.swift | 2 +- Sources/Observing/ListMonitor.swift | 4 ++-- Sources/Observing/ObjectMonitor.swift | 4 ++-- Sources/Transactions/Into.swift | 2 +- 29 files changed, 81 insertions(+), 56 deletions(-) diff --git a/Sources/Fetching and Querying/Concrete Clauses/From.swift b/Sources/Fetching and Querying/Concrete Clauses/From.swift index c0bb44e..c294958 100644 --- a/Sources/Fetching and Querying/Concrete Clauses/From.swift +++ b/Sources/Fetching and Querying/Concrete Clauses/From.swift @@ -206,7 +206,7 @@ public struct From { return stores?.isEmpty == false } - internal func upcast() -> From { + internal func downcast() -> From { return From( entityClass: self.entityClass, diff --git a/Sources/Importing/CoreDataNativeType.swift b/Sources/Importing/CoreDataNativeType.swift index 5216d5e..16df1e1 100644 --- a/Sources/Importing/CoreDataNativeType.swift +++ b/Sources/Importing/CoreDataNativeType.swift @@ -169,7 +169,7 @@ extension Bool: CoreStoreSupportedAttributeType { public static func cs_fromNativeType(_ value: CoreStoreNativeType) -> Bool? { - return value as Bool + return value.boolValue } public func cs_toNativeType() -> CoreStoreNativeType { @@ -184,7 +184,7 @@ extension Int16: CoreStoreSupportedAttributeType { public static func cs_fromNativeType(_ value: CoreStoreNativeType) -> Int16? { - return value as Int16 + return value.int16Value } public func cs_toNativeType() -> CoreStoreNativeType { @@ -199,7 +199,7 @@ extension Int32: CoreStoreSupportedAttributeType { public static func cs_fromNativeType(_ value: CoreStoreNativeType) -> Int32? { - return value as Int32 + return value.int32Value } public func cs_toNativeType() -> CoreStoreNativeType { @@ -214,7 +214,7 @@ extension Int64: CoreStoreSupportedAttributeType { public static func cs_fromNativeType(_ value: CoreStoreNativeType) -> Int64? { - return value as Int64 + return value.int64Value } public func cs_toNativeType() -> CoreStoreNativeType { @@ -229,7 +229,7 @@ extension Double: CoreStoreSupportedAttributeType { public static func cs_fromNativeType(_ value: CoreStoreNativeType) -> Double? { - return value as Double + return value.doubleValue } public func cs_toNativeType() -> CoreStoreNativeType { @@ -244,7 +244,7 @@ extension Float: CoreStoreSupportedAttributeType { public static func cs_fromNativeType(_ value: CoreStoreNativeType) -> Float? { - return value as Float + return value.floatValue } public func cs_toNativeType() -> CoreStoreNativeType { diff --git a/Sources/Internal/NSManagedObjectModel+Setup.swift b/Sources/Internal/NSManagedObjectModel+Setup.swift index 033f730..8594d65 100644 --- a/Sources/Internal/NSManagedObjectModel+Setup.swift +++ b/Sources/Internal/NSManagedObjectModel+Setup.swift @@ -123,7 +123,7 @@ internal extension NSManagedObjectModel { &PropertyKeys.currentModelVersion, inObject: self ) - return value as? String + return value as String? } set { diff --git a/Sources/ObjectiveC/CSAsynchronousDataTransaction.swift b/Sources/ObjectiveC/CSAsynchronousDataTransaction.swift index f8b3846..aad2458 100644 --- a/Sources/ObjectiveC/CSAsynchronousDataTransaction.swift +++ b/Sources/ObjectiveC/CSAsynchronousDataTransaction.swift @@ -168,5 +168,8 @@ extension AsynchronousDataTransaction: CoreStoreSwiftType { // MARK: CoreStoreSwiftType - public typealias ObjectiveCType = CSAsynchronousDataTransaction + public var bridgeToObjectiveC: CSAsynchronousDataTransaction { + + return CSAsynchronousDataTransaction(self) + } } diff --git a/Sources/ObjectiveC/CSBaseDataTransaction.swift b/Sources/ObjectiveC/CSBaseDataTransaction.swift index b55db0e..ce996ff 100644 --- a/Sources/ObjectiveC/CSBaseDataTransaction.swift +++ b/Sources/ObjectiveC/CSBaseDataTransaction.swift @@ -294,13 +294,3 @@ public class CSBaseDataTransaction: NSObject, CoreStoreObjectiveCType { private let swiftTransaction: BaseDataTransaction } - - -//// MARK: - BaseDataTransaction -// -//extension BaseDataTransaction: CoreStoreSwiftType { -// -// // MARK: CoreStoreSwiftType -// -// public typealias ObjectiveCType = CSBaseDataTransaction -//} diff --git a/Sources/ObjectiveC/CSDataStack.swift b/Sources/ObjectiveC/CSDataStack.swift index 4965144..386dd27 100644 --- a/Sources/ObjectiveC/CSDataStack.swift +++ b/Sources/ObjectiveC/CSDataStack.swift @@ -277,5 +277,8 @@ extension DataStack: CoreStoreSwiftType { // MARK: CoreStoreSwiftType - public typealias ObjectiveCType = CSDataStack + public var bridgeToObjectiveC: CSDataStack { + + return CSDataStack(self) + } } diff --git a/Sources/ObjectiveC/CSFrom.swift b/Sources/ObjectiveC/CSFrom.swift index 71d8c6b..66677aa 100644 --- a/Sources/ObjectiveC/CSFrom.swift +++ b/Sources/ObjectiveC/CSFrom.swift @@ -146,7 +146,7 @@ public final class CSFrom: NSObject, CoreStoreObjectiveCType { public init(_ swiftValue: From) { - self.bridgeToSwift = swiftValue.upcast() + self.bridgeToSwift = swiftValue.downcast() super.init() } } diff --git a/Sources/ObjectiveC/CSGroupBy.swift b/Sources/ObjectiveC/CSGroupBy.swift index 2c1eaf0..27c331d 100644 --- a/Sources/ObjectiveC/CSGroupBy.swift +++ b/Sources/ObjectiveC/CSGroupBy.swift @@ -118,5 +118,8 @@ extension GroupBy: CoreStoreSwiftType { // MARK: CoreStoreSwiftType - public typealias ObjectiveCType = CSGroupBy + public var bridgeToObjectiveC: CSGroupBy { + + return CSGroupBy(self) + } } diff --git a/Sources/ObjectiveC/CSInMemoryStore.swift b/Sources/ObjectiveC/CSInMemoryStore.swift index 2aa9e13..1efc847 100644 --- a/Sources/ObjectiveC/CSInMemoryStore.swift +++ b/Sources/ObjectiveC/CSInMemoryStore.swift @@ -125,5 +125,8 @@ extension InMemoryStore: CoreStoreSwiftType { // MARK: CoreStoreSwiftType - public typealias ObjectiveCType = CSInMemoryStore + public var bridgeToObjectiveC: CSInMemoryStore { + + return CSInMemoryStore(self) + } } diff --git a/Sources/ObjectiveC/CSInto.swift b/Sources/ObjectiveC/CSInto.swift index 080ee04..4e783bb 100644 --- a/Sources/ObjectiveC/CSInto.swift +++ b/Sources/ObjectiveC/CSInto.swift @@ -114,7 +114,7 @@ public final class CSInto: NSObject, CoreStoreObjectiveCType { public required init(_ swiftValue: Into) { - self.bridgeToSwift = swiftValue.upcast() + self.bridgeToSwift = swiftValue.downcast() super.init() } } diff --git a/Sources/ObjectiveC/CSListMonitor.swift b/Sources/ObjectiveC/CSListMonitor.swift index 5b9c359..8a9b6c5 100644 --- a/Sources/ObjectiveC/CSListMonitor.swift +++ b/Sources/ObjectiveC/CSListMonitor.swift @@ -538,7 +538,7 @@ public final class CSListMonitor: NSObject, CoreStoreObjectiveCType { @nonobjc public required init(_ swiftValue: ListMonitor) { - self.bridgeToSwift = swiftValue.upcast() + self.bridgeToSwift = swiftValue.downcast() super.init() } } diff --git a/Sources/ObjectiveC/CSMigrationResult.swift b/Sources/ObjectiveC/CSMigrationResult.swift index 56fac06..f6b3bea 100644 --- a/Sources/ObjectiveC/CSMigrationResult.swift +++ b/Sources/ObjectiveC/CSMigrationResult.swift @@ -177,5 +177,8 @@ extension MigrationResult: CoreStoreSwiftType { // MARK: CoreStoreSwiftType - public typealias ObjectiveCType = CSMigrationResult + public var bridgeToObjectiveC: CSMigrationResult { + + return CSMigrationResult(self) + } } diff --git a/Sources/ObjectiveC/CSMigrationType.swift b/Sources/ObjectiveC/CSMigrationType.swift index 385adbf..ee17b8f 100644 --- a/Sources/ObjectiveC/CSMigrationType.swift +++ b/Sources/ObjectiveC/CSMigrationType.swift @@ -123,5 +123,8 @@ extension MigrationType: CoreStoreSwiftType { // MARK: CoreStoreSwiftType - public typealias ObjectiveCType = CSMigrationType + public var bridgeToObjectiveC: CSMigrationType { + + return CSMigrationType(self) + } } diff --git a/Sources/ObjectiveC/CSObjectMonitor.swift b/Sources/ObjectiveC/CSObjectMonitor.swift index 0625fee..5b8bfc7 100644 --- a/Sources/ObjectiveC/CSObjectMonitor.swift +++ b/Sources/ObjectiveC/CSObjectMonitor.swift @@ -130,7 +130,7 @@ public final class CSObjectMonitor: NSObject, CoreStoreObjectiveCType { @nonobjc public required init(_ swiftValue: ObjectMonitor) { - self.bridgeToSwift = swiftValue.upcast() + self.bridgeToSwift = swiftValue.downcast() super.init() } } diff --git a/Sources/ObjectiveC/CSOrderBy.swift b/Sources/ObjectiveC/CSOrderBy.swift index 53c97a9..a7928ff 100644 --- a/Sources/ObjectiveC/CSOrderBy.swift +++ b/Sources/ObjectiveC/CSOrderBy.swift @@ -126,5 +126,8 @@ extension OrderBy: CoreStoreSwiftType { // MARK: CoreStoreSwiftType - public typealias ObjectiveCType = CSOrderBy + public var bridgeToObjectiveC: CSOrderBy { + + return CSOrderBy(self) + } } diff --git a/Sources/ObjectiveC/CSSQliteStore.swift b/Sources/ObjectiveC/CSSQliteStore.swift index f449c76..6ef96c9 100644 --- a/Sources/ObjectiveC/CSSQliteStore.swift +++ b/Sources/ObjectiveC/CSSQliteStore.swift @@ -203,5 +203,8 @@ extension SQLiteStore: CoreStoreSwiftType { // MARK: CoreStoreSwiftType - public typealias ObjectiveCType = CSSQLiteStore + public var bridgeToObjectiveC: CSSQLiteStore { + + return CSSQLiteStore(self) + } } diff --git a/Sources/ObjectiveC/CSSaveResult.swift b/Sources/ObjectiveC/CSSaveResult.swift index 863e5bd..3fe7063 100644 --- a/Sources/ObjectiveC/CSSaveResult.swift +++ b/Sources/ObjectiveC/CSSaveResult.swift @@ -177,5 +177,8 @@ extension SaveResult: CoreStoreSwiftType { // MARK: CoreStoreSwiftType - public typealias ObjectiveCType = CSSaveResult + public var bridgeToObjectiveC: CSSaveResult { + + return CSSaveResult(self) + } } diff --git a/Sources/ObjectiveC/CSSectionBy.swift b/Sources/ObjectiveC/CSSectionBy.swift index 5a77951..91b578e 100644 --- a/Sources/ObjectiveC/CSSectionBy.swift +++ b/Sources/ObjectiveC/CSSectionBy.swift @@ -91,7 +91,10 @@ extension SectionBy: CoreStoreSwiftType { // MARK: CoreStoreSwiftType - public typealias ObjectiveCType = CSSectionBy + public var bridgeToObjectiveC: CSSectionBy { + + return CSSectionBy(self) + } } #endif diff --git a/Sources/ObjectiveC/CSSelect.swift b/Sources/ObjectiveC/CSSelect.swift index 3311019..dca03f2 100644 --- a/Sources/ObjectiveC/CSSelect.swift +++ b/Sources/ObjectiveC/CSSelect.swift @@ -192,7 +192,10 @@ extension SelectTerm: CoreStoreSwiftType { // MARK: CoreStoreSwiftType - public typealias ObjectiveCType = CSSelectTerm + public var bridgeToObjectiveC: CSSelectTerm { + + return CSSelectTerm(self) + } } diff --git a/Sources/ObjectiveC/CSSetupResult.swift b/Sources/ObjectiveC/CSSetupResult.swift index fe2d383..124b255 100644 --- a/Sources/ObjectiveC/CSSetupResult.swift +++ b/Sources/ObjectiveC/CSSetupResult.swift @@ -181,8 +181,6 @@ extension SetupResult where T: CoreStoreSwiftType, T.ObjectiveCType: CSStorageIn // MARK: CoreStoreSwiftType - public typealias ObjectiveCType = CSSetupResult - public var bridgeToObjectiveC: CSSetupResult { return CSSetupResult(self) diff --git a/Sources/ObjectiveC/CSSynchronousDataTransaction.swift b/Sources/ObjectiveC/CSSynchronousDataTransaction.swift index 8a8f7ed..812964d 100644 --- a/Sources/ObjectiveC/CSSynchronousDataTransaction.swift +++ b/Sources/ObjectiveC/CSSynchronousDataTransaction.swift @@ -167,5 +167,8 @@ extension SynchronousDataTransaction: CoreStoreSwiftType { // MARK: CoreStoreSwiftType - public typealias ObjectiveCType = CSSynchronousDataTransaction + public var bridgeToObjectiveC: CSSynchronousDataTransaction { + + return CSSynchronousDataTransaction(self) + } } diff --git a/Sources/ObjectiveC/CSTweak.swift b/Sources/ObjectiveC/CSTweak.swift index 5e0654b..6e2c09f 100644 --- a/Sources/ObjectiveC/CSTweak.swift +++ b/Sources/ObjectiveC/CSTweak.swift @@ -94,5 +94,8 @@ extension Tweak: CoreStoreSwiftType { // MARK: CoreStoreSwiftType - public typealias ObjectiveCType = CSTweak + public var bridgeToObjectiveC: CSTweak { + + return CSTweak(self) + } } diff --git a/Sources/ObjectiveC/CSUnsafeDataTransaction.swift b/Sources/ObjectiveC/CSUnsafeDataTransaction.swift index 44bc587..f42388a 100644 --- a/Sources/ObjectiveC/CSUnsafeDataTransaction.swift +++ b/Sources/ObjectiveC/CSUnsafeDataTransaction.swift @@ -197,5 +197,8 @@ extension UnsafeDataTransaction: CoreStoreSwiftType { // MARK: CoreStoreSwiftType - public typealias ObjectiveCType = CSUnsafeDataTransaction + public var bridgeToObjectiveC: CSUnsafeDataTransaction { + + return CSUnsafeDataTransaction(self) + } } diff --git a/Sources/ObjectiveC/CSWhere.swift b/Sources/ObjectiveC/CSWhere.swift index ea1926a..ae021be 100644 --- a/Sources/ObjectiveC/CSWhere.swift +++ b/Sources/ObjectiveC/CSWhere.swift @@ -163,5 +163,8 @@ extension Where: CoreStoreSwiftType { // MARK: CoreStoreSwiftType - public typealias ObjectiveCType = CSWhere + public var bridgeToObjectiveC: CSWhere { + + return CSWhere(self) + } } diff --git a/Sources/ObjectiveC/CoreStoreBridge.swift b/Sources/ObjectiveC/CoreStoreBridge.swift index 3d94843..468f3c0 100644 --- a/Sources/ObjectiveC/CoreStoreBridge.swift +++ b/Sources/ObjectiveC/CoreStoreBridge.swift @@ -68,28 +68,20 @@ public protocol CoreStoreSwiftType { var bridgeToObjectiveC: ObjectiveCType { get } } -public extension CoreStoreSwiftType where ObjectiveCType: CoreStoreObjectiveCType, Self == ObjectiveCType.SwiftType { - - public var bridgeToObjectiveC: ObjectiveCType { - - return ObjectiveCType(self) - } -} - // MARK: - Internal -internal func bridge(_ closure: () -> T) -> T.ObjectiveCType where T.ObjectiveCType: CoreStoreObjectiveCType, T == T.ObjectiveCType.SwiftType { +internal func bridge(_ closure: () -> T) -> T.ObjectiveCType { return closure().bridgeToObjectiveC } -internal func bridge(_ closure: () -> T?) -> T.ObjectiveCType? where T.ObjectiveCType: CoreStoreObjectiveCType, T == T.ObjectiveCType.SwiftType { +internal func bridge(_ closure: () -> T?) -> T.ObjectiveCType? { return closure()?.bridgeToObjectiveC } -internal func bridge(_ closure: () throws -> T) throws -> T.ObjectiveCType where T.ObjectiveCType: CoreStoreObjectiveCType, T == T.ObjectiveCType.SwiftType { +internal func bridge(_ closure: () throws -> T) throws -> T.ObjectiveCType { do { diff --git a/Sources/ObjectiveC/NSFetchedResultsController+ObjectiveC.swift b/Sources/ObjectiveC/NSFetchedResultsController+ObjectiveC.swift index 66dee61..ed7de1f 100644 --- a/Sources/ObjectiveC/NSFetchedResultsController+ObjectiveC.swift +++ b/Sources/ObjectiveC/NSFetchedResultsController+ObjectiveC.swift @@ -88,7 +88,7 @@ fileprivate func createFRC(fromContext context: NSManagedObjectContext, from: CS let controller = CoreStoreFetchedResultsController( context: context, fetchRequest: CoreStoreFetchRequest().dynamicCast(), - from: from?.bridgeToSwift.upcast(), + from: from?.bridgeToSwift.downcast(), sectionBy: sectionBy?.bridgeToSwift, applyFetchClauses: { (fetchRequest) in diff --git a/Sources/Observing/ListMonitor.swift b/Sources/Observing/ListMonitor.swift index 38a4ec8..cf69710 100644 --- a/Sources/Observing/ListMonitor.swift +++ b/Sources/Observing/ListMonitor.swift @@ -675,9 +675,9 @@ public final class ListMonitor: Hashable { ) } - internal func upcast() -> ListMonitor { + internal func downcast() -> ListMonitor { - return unsafeBitCast(self, to: ListMonitor.self) + return unsafeDowncast(self, to: ListMonitor.self) } internal func registerChangeNotification(_ notificationKey: UnsafeRawPointer, name: Notification.Name, toObserver observer: AnyObject, callback: @escaping (_ monitor: ListMonitor) -> Void) { diff --git a/Sources/Observing/ObjectMonitor.swift b/Sources/Observing/ObjectMonitor.swift index 5db3b32..bc9add6 100644 --- a/Sources/Observing/ObjectMonitor.swift +++ b/Sources/Observing/ObjectMonitor.swift @@ -210,9 +210,9 @@ public final class ObjectMonitor: Equatable { cs_setAssociatedRetainedObject(nilValue, forKey: &self.didUpdateObjectKey, inObject: observer) } - internal func upcast() -> ObjectMonitor { + internal func downcast() -> ObjectMonitor { - return unsafeBitCast(self, to: ObjectMonitor.self) + return unsafeDowncast(self, to: ObjectMonitor.self) } deinit { diff --git a/Sources/Transactions/Into.swift b/Sources/Transactions/Into.swift index cc9666f..45e273a 100644 --- a/Sources/Transactions/Into.swift +++ b/Sources/Transactions/Into.swift @@ -163,7 +163,7 @@ public struct Into: Hashable { internal let inferStoreIfPossible: Bool - internal func upcast() -> Into { + internal func downcast() -> Into { return Into( entityClass: self.entityClass,