mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-03-29 22:01:56 +02:00
swift 3.1 support
This commit is contained in:
@@ -206,7 +206,7 @@ public struct From<T: NSManagedObject> {
|
|||||||
return stores?.isEmpty == false
|
return stores?.isEmpty == false
|
||||||
}
|
}
|
||||||
|
|
||||||
internal func upcast() -> From<NSManagedObject> {
|
internal func downcast() -> From<NSManagedObject> {
|
||||||
|
|
||||||
return From<NSManagedObject>(
|
return From<NSManagedObject>(
|
||||||
entityClass: self.entityClass,
|
entityClass: self.entityClass,
|
||||||
|
|||||||
@@ -169,7 +169,7 @@ extension Bool: CoreStoreSupportedAttributeType {
|
|||||||
|
|
||||||
public static func cs_fromNativeType(_ value: CoreStoreNativeType) -> Bool? {
|
public static func cs_fromNativeType(_ value: CoreStoreNativeType) -> Bool? {
|
||||||
|
|
||||||
return value as Bool
|
return value.boolValue
|
||||||
}
|
}
|
||||||
|
|
||||||
public func cs_toNativeType() -> CoreStoreNativeType {
|
public func cs_toNativeType() -> CoreStoreNativeType {
|
||||||
@@ -184,7 +184,7 @@ extension Int16: CoreStoreSupportedAttributeType {
|
|||||||
|
|
||||||
public static func cs_fromNativeType(_ value: CoreStoreNativeType) -> Int16? {
|
public static func cs_fromNativeType(_ value: CoreStoreNativeType) -> Int16? {
|
||||||
|
|
||||||
return value as Int16
|
return value.int16Value
|
||||||
}
|
}
|
||||||
|
|
||||||
public func cs_toNativeType() -> CoreStoreNativeType {
|
public func cs_toNativeType() -> CoreStoreNativeType {
|
||||||
@@ -199,7 +199,7 @@ extension Int32: CoreStoreSupportedAttributeType {
|
|||||||
|
|
||||||
public static func cs_fromNativeType(_ value: CoreStoreNativeType) -> Int32? {
|
public static func cs_fromNativeType(_ value: CoreStoreNativeType) -> Int32? {
|
||||||
|
|
||||||
return value as Int32
|
return value.int32Value
|
||||||
}
|
}
|
||||||
|
|
||||||
public func cs_toNativeType() -> CoreStoreNativeType {
|
public func cs_toNativeType() -> CoreStoreNativeType {
|
||||||
@@ -214,7 +214,7 @@ extension Int64: CoreStoreSupportedAttributeType {
|
|||||||
|
|
||||||
public static func cs_fromNativeType(_ value: CoreStoreNativeType) -> Int64? {
|
public static func cs_fromNativeType(_ value: CoreStoreNativeType) -> Int64? {
|
||||||
|
|
||||||
return value as Int64
|
return value.int64Value
|
||||||
}
|
}
|
||||||
|
|
||||||
public func cs_toNativeType() -> CoreStoreNativeType {
|
public func cs_toNativeType() -> CoreStoreNativeType {
|
||||||
@@ -229,7 +229,7 @@ extension Double: CoreStoreSupportedAttributeType {
|
|||||||
|
|
||||||
public static func cs_fromNativeType(_ value: CoreStoreNativeType) -> Double? {
|
public static func cs_fromNativeType(_ value: CoreStoreNativeType) -> Double? {
|
||||||
|
|
||||||
return value as Double
|
return value.doubleValue
|
||||||
}
|
}
|
||||||
|
|
||||||
public func cs_toNativeType() -> CoreStoreNativeType {
|
public func cs_toNativeType() -> CoreStoreNativeType {
|
||||||
@@ -244,7 +244,7 @@ extension Float: CoreStoreSupportedAttributeType {
|
|||||||
|
|
||||||
public static func cs_fromNativeType(_ value: CoreStoreNativeType) -> Float? {
|
public static func cs_fromNativeType(_ value: CoreStoreNativeType) -> Float? {
|
||||||
|
|
||||||
return value as Float
|
return value.floatValue
|
||||||
}
|
}
|
||||||
|
|
||||||
public func cs_toNativeType() -> CoreStoreNativeType {
|
public func cs_toNativeType() -> CoreStoreNativeType {
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ internal extension NSManagedObjectModel {
|
|||||||
&PropertyKeys.currentModelVersion,
|
&PropertyKeys.currentModelVersion,
|
||||||
inObject: self
|
inObject: self
|
||||||
)
|
)
|
||||||
return value as? String
|
return value as String?
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
|
|
||||||
|
|||||||
@@ -168,5 +168,8 @@ extension AsynchronousDataTransaction: CoreStoreSwiftType {
|
|||||||
|
|
||||||
// MARK: CoreStoreSwiftType
|
// MARK: CoreStoreSwiftType
|
||||||
|
|
||||||
public typealias ObjectiveCType = CSAsynchronousDataTransaction
|
public var bridgeToObjectiveC: CSAsynchronousDataTransaction {
|
||||||
|
|
||||||
|
return CSAsynchronousDataTransaction(self)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -294,13 +294,3 @@ public class CSBaseDataTransaction: NSObject, CoreStoreObjectiveCType {
|
|||||||
|
|
||||||
private let swiftTransaction: BaseDataTransaction
|
private let swiftTransaction: BaseDataTransaction
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//// MARK: - BaseDataTransaction
|
|
||||||
//
|
|
||||||
//extension BaseDataTransaction: CoreStoreSwiftType {
|
|
||||||
//
|
|
||||||
// // MARK: CoreStoreSwiftType
|
|
||||||
//
|
|
||||||
// public typealias ObjectiveCType = CSBaseDataTransaction
|
|
||||||
//}
|
|
||||||
|
|||||||
@@ -277,5 +277,8 @@ extension DataStack: CoreStoreSwiftType {
|
|||||||
|
|
||||||
// MARK: CoreStoreSwiftType
|
// MARK: CoreStoreSwiftType
|
||||||
|
|
||||||
public typealias ObjectiveCType = CSDataStack
|
public var bridgeToObjectiveC: CSDataStack {
|
||||||
|
|
||||||
|
return CSDataStack(self)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -146,7 +146,7 @@ public final class CSFrom: NSObject, CoreStoreObjectiveCType {
|
|||||||
|
|
||||||
public init<T: NSManagedObject>(_ swiftValue: From<T>) {
|
public init<T: NSManagedObject>(_ swiftValue: From<T>) {
|
||||||
|
|
||||||
self.bridgeToSwift = swiftValue.upcast()
|
self.bridgeToSwift = swiftValue.downcast()
|
||||||
super.init()
|
super.init()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -118,5 +118,8 @@ extension GroupBy: CoreStoreSwiftType {
|
|||||||
|
|
||||||
// MARK: CoreStoreSwiftType
|
// MARK: CoreStoreSwiftType
|
||||||
|
|
||||||
public typealias ObjectiveCType = CSGroupBy
|
public var bridgeToObjectiveC: CSGroupBy {
|
||||||
|
|
||||||
|
return CSGroupBy(self)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -125,5 +125,8 @@ extension InMemoryStore: CoreStoreSwiftType {
|
|||||||
|
|
||||||
// MARK: CoreStoreSwiftType
|
// MARK: CoreStoreSwiftType
|
||||||
|
|
||||||
public typealias ObjectiveCType = CSInMemoryStore
|
public var bridgeToObjectiveC: CSInMemoryStore {
|
||||||
|
|
||||||
|
return CSInMemoryStore(self)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ public final class CSInto: NSObject, CoreStoreObjectiveCType {
|
|||||||
|
|
||||||
public required init<T: NSManagedObject>(_ swiftValue: Into<T>) {
|
public required init<T: NSManagedObject>(_ swiftValue: Into<T>) {
|
||||||
|
|
||||||
self.bridgeToSwift = swiftValue.upcast()
|
self.bridgeToSwift = swiftValue.downcast()
|
||||||
super.init()
|
super.init()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -538,7 +538,7 @@ public final class CSListMonitor: NSObject, CoreStoreObjectiveCType {
|
|||||||
@nonobjc
|
@nonobjc
|
||||||
public required init<T: NSManagedObject>(_ swiftValue: ListMonitor<T>) {
|
public required init<T: NSManagedObject>(_ swiftValue: ListMonitor<T>) {
|
||||||
|
|
||||||
self.bridgeToSwift = swiftValue.upcast()
|
self.bridgeToSwift = swiftValue.downcast()
|
||||||
super.init()
|
super.init()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -177,5 +177,8 @@ extension MigrationResult: CoreStoreSwiftType {
|
|||||||
|
|
||||||
// MARK: CoreStoreSwiftType
|
// MARK: CoreStoreSwiftType
|
||||||
|
|
||||||
public typealias ObjectiveCType = CSMigrationResult
|
public var bridgeToObjectiveC: CSMigrationResult {
|
||||||
|
|
||||||
|
return CSMigrationResult(self)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -123,5 +123,8 @@ extension MigrationType: CoreStoreSwiftType {
|
|||||||
|
|
||||||
// MARK: CoreStoreSwiftType
|
// MARK: CoreStoreSwiftType
|
||||||
|
|
||||||
public typealias ObjectiveCType = CSMigrationType
|
public var bridgeToObjectiveC: CSMigrationType {
|
||||||
|
|
||||||
|
return CSMigrationType(self)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ public final class CSObjectMonitor: NSObject, CoreStoreObjectiveCType {
|
|||||||
@nonobjc
|
@nonobjc
|
||||||
public required init<T: NSManagedObject>(_ swiftValue: ObjectMonitor<T>) {
|
public required init<T: NSManagedObject>(_ swiftValue: ObjectMonitor<T>) {
|
||||||
|
|
||||||
self.bridgeToSwift = swiftValue.upcast()
|
self.bridgeToSwift = swiftValue.downcast()
|
||||||
super.init()
|
super.init()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -126,5 +126,8 @@ extension OrderBy: CoreStoreSwiftType {
|
|||||||
|
|
||||||
// MARK: CoreStoreSwiftType
|
// MARK: CoreStoreSwiftType
|
||||||
|
|
||||||
public typealias ObjectiveCType = CSOrderBy
|
public var bridgeToObjectiveC: CSOrderBy {
|
||||||
|
|
||||||
|
return CSOrderBy(self)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -203,5 +203,8 @@ extension SQLiteStore: CoreStoreSwiftType {
|
|||||||
|
|
||||||
// MARK: CoreStoreSwiftType
|
// MARK: CoreStoreSwiftType
|
||||||
|
|
||||||
public typealias ObjectiveCType = CSSQLiteStore
|
public var bridgeToObjectiveC: CSSQLiteStore {
|
||||||
|
|
||||||
|
return CSSQLiteStore(self)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -177,5 +177,8 @@ extension SaveResult: CoreStoreSwiftType {
|
|||||||
|
|
||||||
// MARK: CoreStoreSwiftType
|
// MARK: CoreStoreSwiftType
|
||||||
|
|
||||||
public typealias ObjectiveCType = CSSaveResult
|
public var bridgeToObjectiveC: CSSaveResult {
|
||||||
|
|
||||||
|
return CSSaveResult(self)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -91,7 +91,10 @@ extension SectionBy: CoreStoreSwiftType {
|
|||||||
|
|
||||||
// MARK: CoreStoreSwiftType
|
// MARK: CoreStoreSwiftType
|
||||||
|
|
||||||
public typealias ObjectiveCType = CSSectionBy
|
public var bridgeToObjectiveC: CSSectionBy {
|
||||||
|
|
||||||
|
return CSSectionBy(self)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -192,7 +192,10 @@ extension SelectTerm: CoreStoreSwiftType {
|
|||||||
|
|
||||||
// MARK: CoreStoreSwiftType
|
// MARK: CoreStoreSwiftType
|
||||||
|
|
||||||
public typealias ObjectiveCType = CSSelectTerm
|
public var bridgeToObjectiveC: CSSelectTerm {
|
||||||
|
|
||||||
|
return CSSelectTerm(self)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -181,8 +181,6 @@ extension SetupResult where T: CoreStoreSwiftType, T.ObjectiveCType: CSStorageIn
|
|||||||
|
|
||||||
// MARK: CoreStoreSwiftType
|
// MARK: CoreStoreSwiftType
|
||||||
|
|
||||||
public typealias ObjectiveCType = CSSetupResult
|
|
||||||
|
|
||||||
public var bridgeToObjectiveC: CSSetupResult {
|
public var bridgeToObjectiveC: CSSetupResult {
|
||||||
|
|
||||||
return CSSetupResult(self)
|
return CSSetupResult(self)
|
||||||
|
|||||||
@@ -167,5 +167,8 @@ extension SynchronousDataTransaction: CoreStoreSwiftType {
|
|||||||
|
|
||||||
// MARK: CoreStoreSwiftType
|
// MARK: CoreStoreSwiftType
|
||||||
|
|
||||||
public typealias ObjectiveCType = CSSynchronousDataTransaction
|
public var bridgeToObjectiveC: CSSynchronousDataTransaction {
|
||||||
|
|
||||||
|
return CSSynchronousDataTransaction(self)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -94,5 +94,8 @@ extension Tweak: CoreStoreSwiftType {
|
|||||||
|
|
||||||
// MARK: CoreStoreSwiftType
|
// MARK: CoreStoreSwiftType
|
||||||
|
|
||||||
public typealias ObjectiveCType = CSTweak
|
public var bridgeToObjectiveC: CSTweak {
|
||||||
|
|
||||||
|
return CSTweak(self)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -197,5 +197,8 @@ extension UnsafeDataTransaction: CoreStoreSwiftType {
|
|||||||
|
|
||||||
// MARK: CoreStoreSwiftType
|
// MARK: CoreStoreSwiftType
|
||||||
|
|
||||||
public typealias ObjectiveCType = CSUnsafeDataTransaction
|
public var bridgeToObjectiveC: CSUnsafeDataTransaction {
|
||||||
|
|
||||||
|
return CSUnsafeDataTransaction(self)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -163,5 +163,8 @@ extension Where: CoreStoreSwiftType {
|
|||||||
|
|
||||||
// MARK: CoreStoreSwiftType
|
// MARK: CoreStoreSwiftType
|
||||||
|
|
||||||
public typealias ObjectiveCType = CSWhere
|
public var bridgeToObjectiveC: CSWhere {
|
||||||
|
|
||||||
|
return CSWhere(self)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,28 +68,20 @@ public protocol CoreStoreSwiftType {
|
|||||||
var bridgeToObjectiveC: ObjectiveCType { get }
|
var bridgeToObjectiveC: ObjectiveCType { get }
|
||||||
}
|
}
|
||||||
|
|
||||||
public extension CoreStoreSwiftType where ObjectiveCType: CoreStoreObjectiveCType, Self == ObjectiveCType.SwiftType {
|
|
||||||
|
|
||||||
public var bridgeToObjectiveC: ObjectiveCType {
|
|
||||||
|
|
||||||
return ObjectiveCType(self)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// MARK: - Internal
|
// MARK: - Internal
|
||||||
|
|
||||||
internal func bridge<T: CoreStoreSwiftType>(_ closure: () -> T) -> T.ObjectiveCType where T.ObjectiveCType: CoreStoreObjectiveCType, T == T.ObjectiveCType.SwiftType {
|
internal func bridge<T: CoreStoreSwiftType>(_ closure: () -> T) -> T.ObjectiveCType {
|
||||||
|
|
||||||
return closure().bridgeToObjectiveC
|
return closure().bridgeToObjectiveC
|
||||||
}
|
}
|
||||||
|
|
||||||
internal func bridge<T: CoreStoreSwiftType>(_ closure: () -> T?) -> T.ObjectiveCType? where T.ObjectiveCType: CoreStoreObjectiveCType, T == T.ObjectiveCType.SwiftType {
|
internal func bridge<T: CoreStoreSwiftType>(_ closure: () -> T?) -> T.ObjectiveCType? {
|
||||||
|
|
||||||
return closure()?.bridgeToObjectiveC
|
return closure()?.bridgeToObjectiveC
|
||||||
}
|
}
|
||||||
|
|
||||||
internal func bridge<T: CoreStoreSwiftType>(_ closure: () throws -> T) throws -> T.ObjectiveCType where T.ObjectiveCType: CoreStoreObjectiveCType, T == T.ObjectiveCType.SwiftType {
|
internal func bridge<T: CoreStoreSwiftType>(_ closure: () throws -> T) throws -> T.ObjectiveCType {
|
||||||
|
|
||||||
do {
|
do {
|
||||||
|
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ fileprivate func createFRC(fromContext context: NSManagedObjectContext, from: CS
|
|||||||
let controller = CoreStoreFetchedResultsController(
|
let controller = CoreStoreFetchedResultsController(
|
||||||
context: context,
|
context: context,
|
||||||
fetchRequest: CoreStoreFetchRequest().dynamicCast(),
|
fetchRequest: CoreStoreFetchRequest().dynamicCast(),
|
||||||
from: from?.bridgeToSwift.upcast(),
|
from: from?.bridgeToSwift.downcast(),
|
||||||
sectionBy: sectionBy?.bridgeToSwift,
|
sectionBy: sectionBy?.bridgeToSwift,
|
||||||
applyFetchClauses: { (fetchRequest) in
|
applyFetchClauses: { (fetchRequest) in
|
||||||
|
|
||||||
|
|||||||
@@ -675,9 +675,9 @@ public final class ListMonitor<T: NSManagedObject>: Hashable {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
internal func upcast() -> ListMonitor<NSManagedObject> {
|
internal func downcast() -> ListMonitor<NSManagedObject> {
|
||||||
|
|
||||||
return unsafeBitCast(self, to: ListMonitor<NSManagedObject>.self)
|
return unsafeDowncast(self, to: ListMonitor<NSManagedObject>.self)
|
||||||
}
|
}
|
||||||
|
|
||||||
internal func registerChangeNotification(_ notificationKey: UnsafeRawPointer, name: Notification.Name, toObserver observer: AnyObject, callback: @escaping (_ monitor: ListMonitor<T>) -> Void) {
|
internal func registerChangeNotification(_ notificationKey: UnsafeRawPointer, name: Notification.Name, toObserver observer: AnyObject, callback: @escaping (_ monitor: ListMonitor<T>) -> Void) {
|
||||||
|
|||||||
@@ -210,9 +210,9 @@ public final class ObjectMonitor<EntityType: NSManagedObject>: Equatable {
|
|||||||
cs_setAssociatedRetainedObject(nilValue, forKey: &self.didUpdateObjectKey, inObject: observer)
|
cs_setAssociatedRetainedObject(nilValue, forKey: &self.didUpdateObjectKey, inObject: observer)
|
||||||
}
|
}
|
||||||
|
|
||||||
internal func upcast() -> ObjectMonitor<NSManagedObject> {
|
internal func downcast() -> ObjectMonitor<NSManagedObject> {
|
||||||
|
|
||||||
return unsafeBitCast(self, to: ObjectMonitor<NSManagedObject>.self)
|
return unsafeDowncast(self, to: ObjectMonitor<NSManagedObject>.self)
|
||||||
}
|
}
|
||||||
|
|
||||||
deinit {
|
deinit {
|
||||||
|
|||||||
@@ -163,7 +163,7 @@ public struct Into<T: NSManagedObject>: Hashable {
|
|||||||
|
|
||||||
internal let inferStoreIfPossible: Bool
|
internal let inferStoreIfPossible: Bool
|
||||||
|
|
||||||
internal func upcast() -> Into<NSManagedObject> {
|
internal func downcast() -> Into<NSManagedObject> {
|
||||||
|
|
||||||
return Into<NSManagedObject>(
|
return Into<NSManagedObject>(
|
||||||
entityClass: self.entityClass,
|
entityClass: self.entityClass,
|
||||||
|
|||||||
Reference in New Issue
Block a user