mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-01-15 05:33:31 +01:00
allow public access to bridgeToObjectiveC and bridgeToSwift properties
This commit is contained in:
@@ -930,6 +930,7 @@
|
||||
B5DBE2CB1C99148100B5CEFA /* ObjectiveC */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
B5AEFAB41C9962AE00AD137F /* CoreStoreBridge.swift */,
|
||||
B5DBE2CC1C9914A900B5CEFA /* CSCoreStore.swift */,
|
||||
B5519A491CA1F4FB002BEF78 /* CSError.swift */,
|
||||
B546F9611C9A13F400D5AC55 /* Setup */,
|
||||
@@ -944,7 +945,6 @@
|
||||
B5E222211CA4DE5700BA2E95 /* Internal */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
B5AEFAB41C9962AE00AD137F /* CoreStoreBridge.swift */,
|
||||
B5ECDBF81CA804FD00C7F112 /* NSManagedObjectContext+ObjectiveC.swift */,
|
||||
);
|
||||
name = Internal;
|
||||
|
||||
@@ -40,14 +40,14 @@ class ErrorTests: XCTestCase {
|
||||
|
||||
let userInfo: NSDictionary = [:]
|
||||
|
||||
let objcError = error.objc
|
||||
XCTAssertEqual(error, objcError.swift)
|
||||
let objcError = error.bridgeToObjectiveC
|
||||
XCTAssertEqual(error, objcError.bridgeToSwift)
|
||||
XCTAssertEqual(objcError.domain, CoreStoreErrorDomain)
|
||||
XCTAssertEqual(objcError.code, CoreStoreErrorCode.UnknownError.rawValue)
|
||||
XCTAssertEqual(objcError.userInfo, userInfo)
|
||||
|
||||
let objcError2 = objcError.swift.objc
|
||||
XCTAssertEqual(error, objcError2.swift)
|
||||
let objcError2 = objcError.bridgeToSwift.bridgeToObjectiveC
|
||||
XCTAssertEqual(error, objcError2.bridgeToSwift)
|
||||
XCTAssertEqual(objcError2.domain, CoreStoreErrorDomain)
|
||||
XCTAssertEqual(objcError2.code, CoreStoreErrorCode.UnknownError.rawValue)
|
||||
XCTAssertEqual(objcError2.userInfo, userInfo)
|
||||
@@ -63,14 +63,14 @@ class ErrorTests: XCTestCase {
|
||||
let userInfo: NSDictionary = [
|
||||
"existingPersistentStoreURL": dummyURL
|
||||
]
|
||||
let objcError = error.objc
|
||||
XCTAssertEqual(error, objcError.swift)
|
||||
let objcError = error.bridgeToObjectiveC
|
||||
XCTAssertEqual(error, objcError.bridgeToSwift)
|
||||
XCTAssertEqual(objcError.domain, CoreStoreErrorDomain)
|
||||
XCTAssertEqual(objcError.code, CoreStoreErrorCode.DifferentPersistentStoreExistsAtURL.rawValue)
|
||||
XCTAssertEqual(objcError.userInfo, userInfo)
|
||||
|
||||
let objcError2 = objcError.swift.objc
|
||||
XCTAssertEqual(error, objcError2.swift)
|
||||
let objcError2 = objcError.bridgeToSwift.bridgeToObjectiveC
|
||||
XCTAssertEqual(error, objcError2.bridgeToSwift)
|
||||
XCTAssertEqual(objcError2.domain, CoreStoreErrorDomain)
|
||||
XCTAssertEqual(objcError2.code, CoreStoreErrorCode.DifferentPersistentStoreExistsAtURL.rawValue)
|
||||
XCTAssertEqual(objcError2.userInfo, userInfo)
|
||||
@@ -90,14 +90,14 @@ class ErrorTests: XCTestCase {
|
||||
"targetModel": model,
|
||||
"targetModelVersion": version
|
||||
]
|
||||
let objcError = error.objc
|
||||
XCTAssertEqual(error, objcError.swift)
|
||||
let objcError = error.bridgeToObjectiveC
|
||||
XCTAssertEqual(error, objcError.bridgeToSwift)
|
||||
XCTAssertEqual(objcError.domain, CoreStoreErrorDomain)
|
||||
XCTAssertEqual(objcError.code, CoreStoreErrorCode.MappingModelNotFound.rawValue)
|
||||
XCTAssertEqual(objcError.userInfo, userInfo)
|
||||
|
||||
let objcError2 = objcError.swift.objc
|
||||
XCTAssertEqual(error, objcError2.swift)
|
||||
let objcError2 = objcError.bridgeToSwift.bridgeToObjectiveC
|
||||
XCTAssertEqual(error, objcError2.bridgeToSwift)
|
||||
XCTAssertEqual(objcError2.domain, CoreStoreErrorDomain)
|
||||
XCTAssertEqual(objcError2.code, CoreStoreErrorCode.MappingModelNotFound.rawValue)
|
||||
XCTAssertEqual(objcError2.userInfo, userInfo)
|
||||
@@ -112,14 +112,14 @@ class ErrorTests: XCTestCase {
|
||||
let userInfo: NSDictionary = [
|
||||
"localStoreURL": dummyURL
|
||||
]
|
||||
let objcError = error.objc
|
||||
XCTAssertEqual(error, objcError.swift)
|
||||
let objcError = error.bridgeToObjectiveC
|
||||
XCTAssertEqual(error, objcError.bridgeToSwift)
|
||||
XCTAssertEqual(objcError.domain, CoreStoreErrorDomain)
|
||||
XCTAssertEqual(objcError.code, CoreStoreErrorCode.ProgressiveMigrationRequired.rawValue)
|
||||
XCTAssertEqual(objcError.userInfo, userInfo)
|
||||
|
||||
let objcError2 = objcError.swift.objc
|
||||
XCTAssertEqual(error, objcError2.swift)
|
||||
let objcError2 = objcError.bridgeToSwift.bridgeToObjectiveC
|
||||
XCTAssertEqual(error, objcError2.bridgeToSwift)
|
||||
XCTAssertEqual(objcError2.domain, CoreStoreErrorDomain)
|
||||
XCTAssertEqual(objcError2.code, CoreStoreErrorCode.ProgressiveMigrationRequired.rawValue)
|
||||
XCTAssertEqual(objcError2.userInfo, userInfo)
|
||||
@@ -143,14 +143,14 @@ class ErrorTests: XCTestCase {
|
||||
let userInfo: NSDictionary = [
|
||||
"NSError": internalError
|
||||
]
|
||||
let objcError = error.objc
|
||||
XCTAssertEqual(error, objcError.swift)
|
||||
let objcError = error.bridgeToObjectiveC
|
||||
XCTAssertEqual(error, objcError.bridgeToSwift)
|
||||
XCTAssertEqual(objcError.domain, CoreStoreErrorDomain)
|
||||
XCTAssertEqual(objcError.code, CoreStoreErrorCode.InternalError.rawValue)
|
||||
XCTAssertEqual(objcError.userInfo, userInfo)
|
||||
|
||||
let objcError2 = objcError.swift.objc
|
||||
XCTAssertEqual(error, objcError2.swift)
|
||||
let objcError2 = objcError.bridgeToSwift.bridgeToObjectiveC
|
||||
XCTAssertEqual(error, objcError2.bridgeToSwift)
|
||||
XCTAssertEqual(objcError2.domain, CoreStoreErrorDomain)
|
||||
XCTAssertEqual(objcError2.code, CoreStoreErrorCode.InternalError.rawValue)
|
||||
XCTAssertEqual(objcError2.userInfo, userInfo)
|
||||
|
||||
@@ -82,7 +82,7 @@ public enum CoreStoreError: ErrorType, CustomStringConvertible, CustomDebugStrin
|
||||
public var description: String {
|
||||
|
||||
// TODO:
|
||||
return self.objc.description
|
||||
return self.bridgeToObjectiveC.description
|
||||
}
|
||||
|
||||
|
||||
@@ -123,7 +123,7 @@ public enum CoreStoreError: ErrorType, CustomStringConvertible, CustomDebugStrin
|
||||
|
||||
internal init(_ error: ErrorType?) {
|
||||
|
||||
self = error.flatMap { $0.swift } ?? .Unknown
|
||||
self = error.flatMap { $0.bridgeToSwift } ?? .Unknown
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -98,7 +98,7 @@ extension CoreStoreLogger {
|
||||
@available(*, deprecated=2.0.0, message="Use log(error:message:fileName:lineNumber:functionName:) instead.")
|
||||
public func handleError(error error: NSError, message: String, fileName: StaticString, lineNumber: Int, functionName: StaticString) {
|
||||
|
||||
self.log(error: error.swift, message: message, fileName: fileName, lineNumber: lineNumber, functionName: functionName)
|
||||
self.log(error: error.bridgeToSwift, message: message, fileName: fileName, lineNumber: lineNumber, functionName: functionName)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -43,9 +43,9 @@ public final class CSAsynchronousDataTransaction: CSBaseDataTransaction {
|
||||
@objc
|
||||
public func commitWithCompletion(completion: ((result: CSSaveResult) -> Void)?) {
|
||||
|
||||
self.swift.commit { (result) in
|
||||
self.bridgeToSwift.commit { (result) in
|
||||
|
||||
completion?(result: result.objc)
|
||||
completion?(result: result.bridgeToObjectiveC)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,9 +60,9 @@ public final class CSAsynchronousDataTransaction: CSBaseDataTransaction {
|
||||
|
||||
return bridge {
|
||||
|
||||
self.swift.beginSynchronous { (transaction) in
|
||||
self.bridgeToSwift.beginSynchronous { (transaction) in
|
||||
|
||||
closure(transaction: transaction.objc)
|
||||
closure(transaction: transaction.bridgeToObjectiveC)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -79,7 +79,7 @@ public final class CSAsynchronousDataTransaction: CSBaseDataTransaction {
|
||||
@objc
|
||||
public override func createInto(into: CSInto) -> NSManagedObject {
|
||||
|
||||
return self.swift.create(into.swift)
|
||||
return self.bridgeToSwift.create(into.bridgeToSwift)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -92,7 +92,7 @@ public final class CSAsynchronousDataTransaction: CSBaseDataTransaction {
|
||||
@warn_unused_result
|
||||
public override func editObject(object: NSManagedObject?) -> NSManagedObject? {
|
||||
|
||||
return self.swift.edit(object)
|
||||
return self.bridgeToSwift.edit(object)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -106,7 +106,7 @@ public final class CSAsynchronousDataTransaction: CSBaseDataTransaction {
|
||||
@warn_unused_result
|
||||
public override func editInto(into: CSInto, objectID: NSManagedObjectID) -> NSManagedObject? {
|
||||
|
||||
return self.swift.edit(into.swift, objectID)
|
||||
return self.bridgeToSwift.edit(into.bridgeToSwift, objectID)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -117,7 +117,7 @@ public final class CSAsynchronousDataTransaction: CSBaseDataTransaction {
|
||||
@objc
|
||||
public override func deleteObject(object: NSManagedObject?) {
|
||||
|
||||
self.swift.delete(object)
|
||||
self.bridgeToSwift.delete(object)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -128,27 +128,27 @@ public final class CSAsynchronousDataTransaction: CSBaseDataTransaction {
|
||||
@objc
|
||||
public override func deleteObjects(objects: [NSManagedObject]) {
|
||||
|
||||
self.swift.delete(objects)
|
||||
self.bridgeToSwift.delete(objects)
|
||||
}
|
||||
|
||||
|
||||
// MARK: CoreStoreBridge
|
||||
// MARK: CoreStoreObjectiveCType
|
||||
|
||||
internal typealias SwiftType = AsynchronousDataTransaction
|
||||
|
||||
internal override var swift: AsynchronousDataTransaction {
|
||||
public override var bridgeToSwift: AsynchronousDataTransaction {
|
||||
|
||||
return super.swift as! AsynchronousDataTransaction
|
||||
return super.bridgeToSwift as! AsynchronousDataTransaction
|
||||
}
|
||||
|
||||
public required init(_ swiftObject: AsynchronousDataTransaction) {
|
||||
public required init(_ swiftValue: AsynchronousDataTransaction) {
|
||||
|
||||
super.init(swiftObject)
|
||||
super.init(swiftValue)
|
||||
}
|
||||
|
||||
required public init(_ swiftObject: BaseDataTransaction) {
|
||||
public required init(_ swiftValue: BaseDataTransaction) {
|
||||
|
||||
fatalError("init has not been implemented")
|
||||
fatalError("init(_:) requires an AsynchronousDataTransaction instance")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,7 +157,7 @@ public final class CSAsynchronousDataTransaction: CSBaseDataTransaction {
|
||||
|
||||
extension AsynchronousDataTransaction {
|
||||
|
||||
// MARK: CoreStoreBridgeable
|
||||
// MARK: CoreStoreSwiftType
|
||||
|
||||
internal typealias ObjCType = CSAsynchronousDataTransaction
|
||||
internal typealias ObjectiveCType = CSAsynchronousDataTransaction
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ public extension CSBaseDataTransaction {
|
||||
|
||||
do {
|
||||
|
||||
return try self.swift.context.existingObjectWithID(object.objectID)
|
||||
return try self.bridgeToSwift.context.existingObjectWithID(object.objectID)
|
||||
}
|
||||
catch _ {
|
||||
|
||||
@@ -63,7 +63,7 @@ public extension CSBaseDataTransaction {
|
||||
|
||||
do {
|
||||
|
||||
return try self.swift.context.existingObjectWithID(objectID)
|
||||
return try self.bridgeToSwift.context.existingObjectWithID(objectID)
|
||||
}
|
||||
catch _ {
|
||||
|
||||
@@ -81,7 +81,7 @@ public extension CSBaseDataTransaction {
|
||||
@warn_unused_result
|
||||
public func fetchExistingObjects(objects: [NSManagedObject]) -> [NSManagedObject] {
|
||||
|
||||
return objects.flatMap { try? self.swift.context.existingObjectWithID($0.objectID) }
|
||||
return objects.flatMap { try? self.bridgeToSwift.context.existingObjectWithID($0.objectID) }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -94,7 +94,7 @@ public extension CSBaseDataTransaction {
|
||||
@warn_unused_result
|
||||
public func fetchExistingObjectsWithIDs(objectIDs: [NSManagedObjectID]) -> [NSManagedObject] {
|
||||
|
||||
return objectIDs.flatMap { try? self.swift.context.existingObjectWithID($0) }
|
||||
return objectIDs.flatMap { try? self.bridgeToSwift.context.existingObjectWithID($0) }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -109,10 +109,10 @@ public extension CSBaseDataTransaction {
|
||||
public func fetchOneFrom(from: CSFrom, fetchClauses: [CSFetchClause]) -> NSManagedObject? {
|
||||
|
||||
CoreStore.assert(
|
||||
self.swift.isRunningInAllowedQueue(),
|
||||
self.bridgeToSwift.isRunningInAllowedQueue(),
|
||||
"Attempted to fetch from a \(typeName(self)) outside its designated queue."
|
||||
)
|
||||
return self.swift.context.fetchOne(from, fetchClauses)
|
||||
return self.bridgeToSwift.context.fetchOne(from, fetchClauses)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -127,10 +127,10 @@ public extension CSBaseDataTransaction {
|
||||
public func fetchAllFrom(from: CSFrom, fetchClauses: [CSFetchClause]) -> [NSManagedObject]? {
|
||||
|
||||
CoreStore.assert(
|
||||
self.swift.isRunningInAllowedQueue(),
|
||||
self.bridgeToSwift.isRunningInAllowedQueue(),
|
||||
"Attempted to fetch from a \(typeName(self)) outside its designated queue."
|
||||
)
|
||||
return self.swift.context.fetchAll(from, fetchClauses)
|
||||
return self.bridgeToSwift.context.fetchAll(from, fetchClauses)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -145,10 +145,10 @@ public extension CSBaseDataTransaction {
|
||||
public func fetchCountFrom(from: CSFrom, fetchClauses: [CSFetchClause]) -> NSNumber? {
|
||||
|
||||
CoreStore.assert(
|
||||
self.swift.isRunningInAllowedQueue(),
|
||||
self.bridgeToSwift.isRunningInAllowedQueue(),
|
||||
"Attempted to fetch from a \(typeName(self)) outside its designated queue."
|
||||
)
|
||||
return self.swift.context.fetchCount(from, fetchClauses)
|
||||
return self.bridgeToSwift.context.fetchCount(from, fetchClauses)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -163,10 +163,10 @@ public extension CSBaseDataTransaction {
|
||||
public func fetchObjectIDFrom(from: CSFrom, fetchClauses: [CSFetchClause]) -> NSManagedObjectID? {
|
||||
|
||||
CoreStore.assert(
|
||||
self.swift.isRunningInAllowedQueue(),
|
||||
self.bridgeToSwift.isRunningInAllowedQueue(),
|
||||
"Attempted to fetch from a \(typeName(self)) outside its designated queue."
|
||||
)
|
||||
return self.swift.context.fetchObjectID(from, fetchClauses)
|
||||
return self.bridgeToSwift.context.fetchObjectID(from, fetchClauses)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -181,10 +181,10 @@ public extension CSBaseDataTransaction {
|
||||
public func fetchObjectIDsFrom(from: CSFrom, fetchClauses: [CSFetchClause]) -> [NSManagedObjectID]? {
|
||||
|
||||
CoreStore.assert(
|
||||
self.swift.isRunningInAllowedQueue(),
|
||||
self.bridgeToSwift.isRunningInAllowedQueue(),
|
||||
"Attempted to fetch from a \(typeName(self)) outside its designated queue."
|
||||
)
|
||||
return self.swift.context.fetchObjectIDs(from, fetchClauses)
|
||||
return self.bridgeToSwift.context.fetchObjectIDs(from, fetchClauses)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -198,9 +198,9 @@ public extension CSBaseDataTransaction {
|
||||
public func deleteAllFrom(from: CSFrom, deleteClauses: [CSDeleteClause]) -> NSNumber? {
|
||||
|
||||
CoreStore.assert(
|
||||
self.swift.isRunningInAllowedQueue(),
|
||||
self.bridgeToSwift.isRunningInAllowedQueue(),
|
||||
"Attempted to delete from a \(typeName(self)) outside its designated queue."
|
||||
)
|
||||
return self.swift.context.deleteAll(from, deleteClauses)
|
||||
return self.bridgeToSwift.context.deleteAll(from, deleteClauses)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ import CoreData
|
||||
The `CSBaseDataTransaction` serves as the Objective-C bridging type for `BaseDataTransaction`.
|
||||
*/
|
||||
@objc
|
||||
public class CSBaseDataTransaction: NSObject, CoreStoreBridge {
|
||||
public class CSBaseDataTransaction: NSObject, CoreStoreObjectiveCType {
|
||||
|
||||
// MARK: Object management
|
||||
|
||||
@@ -43,7 +43,7 @@ public class CSBaseDataTransaction: NSObject, CoreStoreBridge {
|
||||
@objc
|
||||
public var hasChanges: Bool {
|
||||
|
||||
return self.swift.hasChanges
|
||||
return self.bridgeToSwift.hasChanges
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -55,7 +55,7 @@ public class CSBaseDataTransaction: NSObject, CoreStoreBridge {
|
||||
@objc
|
||||
public func createInto(into: CSInto) -> NSManagedObject {
|
||||
|
||||
return self.swift.create(into.swift)
|
||||
return self.bridgeToSwift.create(into.bridgeToSwift)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -68,7 +68,7 @@ public class CSBaseDataTransaction: NSObject, CoreStoreBridge {
|
||||
@warn_unused_result
|
||||
public func editObject(object: NSManagedObject?) -> NSManagedObject? {
|
||||
|
||||
return self.swift.edit(object)
|
||||
return self.bridgeToSwift.edit(object)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -82,7 +82,7 @@ public class CSBaseDataTransaction: NSObject, CoreStoreBridge {
|
||||
@warn_unused_result
|
||||
public func editInto(into: CSInto, objectID: NSManagedObjectID) -> NSManagedObject? {
|
||||
|
||||
return self.swift.edit(into.swift, objectID)
|
||||
return self.bridgeToSwift.edit(into.bridgeToSwift, objectID)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -93,7 +93,7 @@ public class CSBaseDataTransaction: NSObject, CoreStoreBridge {
|
||||
@objc
|
||||
public func deleteObject(object: NSManagedObject?) {
|
||||
|
||||
self.swift.delete(object)
|
||||
self.bridgeToSwift.delete(object)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -104,7 +104,7 @@ public class CSBaseDataTransaction: NSObject, CoreStoreBridge {
|
||||
@objc
|
||||
public func deleteObjects(objects: [NSManagedObject]) {
|
||||
|
||||
self.swift.delete(objects)
|
||||
self.bridgeToSwift.delete(objects)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -113,7 +113,7 @@ public class CSBaseDataTransaction: NSObject, CoreStoreBridge {
|
||||
@objc
|
||||
public func refreshAllObjectsAsFaults() {
|
||||
|
||||
self.swift.refreshAllObjectsAsFaults()
|
||||
self.bridgeToSwift.refreshAllObjectsAsFaults()
|
||||
}
|
||||
|
||||
|
||||
@@ -128,7 +128,7 @@ public class CSBaseDataTransaction: NSObject, CoreStoreBridge {
|
||||
@warn_unused_result
|
||||
public func insertedObjects() -> Set<NSManagedObject> {
|
||||
|
||||
return self.swift.insertedObjects()
|
||||
return self.bridgeToSwift.insertedObjects()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -141,7 +141,7 @@ public class CSBaseDataTransaction: NSObject, CoreStoreBridge {
|
||||
@warn_unused_result
|
||||
public func insertedObjectsOfType(entity: NSManagedObject.Type) -> Set<NSManagedObject> {
|
||||
|
||||
return self.swift.insertedObjects(entity)
|
||||
return self.bridgeToSwift.insertedObjects(entity)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -153,7 +153,7 @@ public class CSBaseDataTransaction: NSObject, CoreStoreBridge {
|
||||
@warn_unused_result
|
||||
public func insertedObjectIDs() -> Set<NSManagedObjectID> {
|
||||
|
||||
return self.swift.insertedObjectIDs()
|
||||
return self.bridgeToSwift.insertedObjectIDs()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -166,7 +166,7 @@ public class CSBaseDataTransaction: NSObject, CoreStoreBridge {
|
||||
@warn_unused_result
|
||||
public func insertedObjectIDsOfType(entity: NSManagedObject.Type) -> Set<NSManagedObjectID> {
|
||||
|
||||
return self.swift.insertedObjectIDs(entity)
|
||||
return self.bridgeToSwift.insertedObjectIDs(entity)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -178,7 +178,7 @@ public class CSBaseDataTransaction: NSObject, CoreStoreBridge {
|
||||
@warn_unused_result
|
||||
public func updatedObjects() -> Set<NSManagedObject> {
|
||||
|
||||
return self.swift.updatedObjects()
|
||||
return self.bridgeToSwift.updatedObjects()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -191,7 +191,7 @@ public class CSBaseDataTransaction: NSObject, CoreStoreBridge {
|
||||
@warn_unused_result
|
||||
public func updatedObjectsOfType(entity: NSManagedObject.Type) -> Set<NSManagedObject> {
|
||||
|
||||
return self.swift.updatedObjects(entity)
|
||||
return self.bridgeToSwift.updatedObjects(entity)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -203,7 +203,7 @@ public class CSBaseDataTransaction: NSObject, CoreStoreBridge {
|
||||
@warn_unused_result
|
||||
public func updatedObjectIDs() -> Set<NSManagedObjectID> {
|
||||
|
||||
return self.swift.updatedObjectIDs()
|
||||
return self.bridgeToSwift.updatedObjectIDs()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -216,7 +216,7 @@ public class CSBaseDataTransaction: NSObject, CoreStoreBridge {
|
||||
@warn_unused_result
|
||||
public func updatedObjectIDsOfType(entity: NSManagedObject.Type) -> Set<NSManagedObjectID> {
|
||||
|
||||
return self.swift.updatedObjectIDs(entity)
|
||||
return self.bridgeToSwift.updatedObjectIDs(entity)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -228,7 +228,7 @@ public class CSBaseDataTransaction: NSObject, CoreStoreBridge {
|
||||
@warn_unused_result
|
||||
public func deletedObjects() -> Set<NSManagedObject> {
|
||||
|
||||
return self.swift.deletedObjects()
|
||||
return self.bridgeToSwift.deletedObjects()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -241,7 +241,7 @@ public class CSBaseDataTransaction: NSObject, CoreStoreBridge {
|
||||
@warn_unused_result
|
||||
public func deletedObjectsOfType(entity: NSManagedObject.Type) -> Set<NSManagedObject> {
|
||||
|
||||
return self.swift.deletedObjects(entity)
|
||||
return self.bridgeToSwift.deletedObjects(entity)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -254,7 +254,7 @@ public class CSBaseDataTransaction: NSObject, CoreStoreBridge {
|
||||
@warn_unused_result
|
||||
public func deletedObjectIDs() -> Set<NSManagedObjectID> {
|
||||
|
||||
return self.swift.deletedObjectIDs()
|
||||
return self.bridgeToSwift.deletedObjectIDs()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -267,7 +267,7 @@ public class CSBaseDataTransaction: NSObject, CoreStoreBridge {
|
||||
@warn_unused_result
|
||||
public func deletedObjectIDsOfType(entity: NSManagedObject.Type) -> Set<NSManagedObjectID> {
|
||||
|
||||
return self.swift.deletedObjectIDs(entity)
|
||||
return self.bridgeToSwift.deletedObjectIDs(entity)
|
||||
}
|
||||
|
||||
|
||||
@@ -275,7 +275,7 @@ public class CSBaseDataTransaction: NSObject, CoreStoreBridge {
|
||||
|
||||
public override var hash: Int {
|
||||
|
||||
return ObjectIdentifier(self.swift).hashValue
|
||||
return ObjectIdentifier(self.bridgeToSwift).hashValue
|
||||
}
|
||||
|
||||
public override func isEqual(object: AnyObject?) -> Bool {
|
||||
@@ -284,34 +284,37 @@ public class CSBaseDataTransaction: NSObject, CoreStoreBridge {
|
||||
|
||||
return false
|
||||
}
|
||||
return self.swift === object.swift
|
||||
return self.bridgeToSwift === object.bridgeToSwift
|
||||
}
|
||||
|
||||
|
||||
// MARK: CoreStoreBridge
|
||||
// MARK: CoreStoreObjectiveCType
|
||||
|
||||
internal typealias SwiftType = BaseDataTransaction
|
||||
public typealias SwiftType = BaseDataTransaction
|
||||
|
||||
public required init(_ swiftObject: BaseDataTransaction) {
|
||||
public required init(_ swiftValue: BaseDataTransaction) {
|
||||
|
||||
self.swiftObject = swiftObject
|
||||
self.swiftTransaction = swiftValue
|
||||
super.init()
|
||||
}
|
||||
|
||||
internal var swift: BaseDataTransaction {
|
||||
public var bridgeToSwift: BaseDataTransaction {
|
||||
|
||||
return self.swiftObject
|
||||
return self.swiftTransaction
|
||||
}
|
||||
|
||||
private let swiftObject: BaseDataTransaction
|
||||
|
||||
// MARK: Private
|
||||
|
||||
private let swiftTransaction: BaseDataTransaction
|
||||
}
|
||||
|
||||
|
||||
// MARK: - BaseDataTransaction
|
||||
|
||||
extension BaseDataTransaction: CoreStoreBridgeable {
|
||||
extension BaseDataTransaction: CoreStoreSwiftType {
|
||||
|
||||
// MARK: CoreStoreBridgeable
|
||||
// MARK: CoreStoreSwiftType
|
||||
|
||||
internal typealias ObjCType = CSBaseDataTransaction
|
||||
public typealias ObjectiveCType = CSBaseDataTransaction
|
||||
}
|
||||
|
||||
@@ -120,7 +120,7 @@ public extension CSCoreStore {
|
||||
|
||||
return try bridge {
|
||||
|
||||
try CoreStore.addStorageAndWait(storage.swift)
|
||||
try CoreStore.addStorageAndWait(storage.bridgeToSwift)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@ public extension CSCoreStore {
|
||||
|
||||
return try bridge {
|
||||
|
||||
try CoreStore.addStorageAndWait(storage.swift)
|
||||
try CoreStore.addStorageAndWait(storage.bridgeToSwift)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -40,7 +40,7 @@ public extension CSCoreStore {
|
||||
|
||||
return CoreStore.beginAsynchronous { (transaction) in
|
||||
|
||||
closure(transaction: transaction.objc)
|
||||
closure(transaction: transaction.bridgeToObjectiveC)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ public extension CSCoreStore {
|
||||
|
||||
CoreStore.beginSynchronous { (transaction) in
|
||||
|
||||
closure(transaction: transaction.objc)
|
||||
closure(transaction: transaction.bridgeToObjectiveC)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,11 +44,11 @@ public final class CSCoreStore: NSObject {
|
||||
|
||||
get {
|
||||
|
||||
return CoreStore.defaultStack.objc
|
||||
return CoreStore.defaultStack.bridgeToObjectiveC
|
||||
}
|
||||
set {
|
||||
|
||||
CoreStore.defaultStack = newValue.swift
|
||||
CoreStore.defaultStack = newValue.bridgeToSwift
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ public extension CSDataStack {
|
||||
|
||||
do {
|
||||
|
||||
return try self.swift.mainContext.existingObjectWithID(object.objectID)
|
||||
return try self.bridgeToSwift.mainContext.existingObjectWithID(object.objectID)
|
||||
}
|
||||
catch _ {
|
||||
|
||||
@@ -63,7 +63,7 @@ public extension CSDataStack {
|
||||
|
||||
do {
|
||||
|
||||
return try self.swift.mainContext.existingObjectWithID(objectID)
|
||||
return try self.bridgeToSwift.mainContext.existingObjectWithID(objectID)
|
||||
}
|
||||
catch _ {
|
||||
|
||||
@@ -81,7 +81,7 @@ public extension CSDataStack {
|
||||
@warn_unused_result
|
||||
public func fetchExistingObjects(objects: [NSManagedObject]) -> [NSManagedObject] {
|
||||
|
||||
return objects.flatMap { try? self.swift.mainContext.existingObjectWithID($0.objectID) }
|
||||
return objects.flatMap { try? self.bridgeToSwift.mainContext.existingObjectWithID($0.objectID) }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -94,7 +94,7 @@ public extension CSDataStack {
|
||||
@warn_unused_result
|
||||
public func fetchExistingObjectsWithIDs(objectIDs: [NSManagedObjectID]) -> [NSManagedObject] {
|
||||
|
||||
return objectIDs.flatMap { try? self.swift.mainContext.existingObjectWithID($0) }
|
||||
return objectIDs.flatMap { try? self.bridgeToSwift.mainContext.existingObjectWithID($0) }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -112,7 +112,7 @@ public extension CSDataStack {
|
||||
NSThread.isMainThread(),
|
||||
"Attempted to fetch from a \(typeName(self)) outside the main thread."
|
||||
)
|
||||
return self.swift.mainContext.fetchOne(from, fetchClauses)
|
||||
return self.bridgeToSwift.mainContext.fetchOne(from, fetchClauses)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -130,7 +130,7 @@ public extension CSDataStack {
|
||||
NSThread.isMainThread(),
|
||||
"Attempted to fetch from a \(typeName(self)) outside the main thread."
|
||||
)
|
||||
return self.swift.mainContext.fetchAll(from, fetchClauses)
|
||||
return self.bridgeToSwift.mainContext.fetchAll(from, fetchClauses)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -148,7 +148,7 @@ public extension CSDataStack {
|
||||
NSThread.isMainThread(),
|
||||
"Attempted to fetch from a \(typeName(self)) outside the main thread."
|
||||
)
|
||||
return self.swift.mainContext.fetchCount(from, fetchClauses)
|
||||
return self.bridgeToSwift.mainContext.fetchCount(from, fetchClauses)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -166,7 +166,7 @@ public extension CSDataStack {
|
||||
NSThread.isMainThread(),
|
||||
"Attempted to fetch from a \(typeName(self)) outside the main thread."
|
||||
)
|
||||
return self.swift.mainContext.fetchObjectID(from, fetchClauses)
|
||||
return self.bridgeToSwift.mainContext.fetchObjectID(from, fetchClauses)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -184,7 +184,7 @@ public extension CSDataStack {
|
||||
NSThread.isMainThread(),
|
||||
"Attempted to fetch from a \(typeName(self)) outside the main thread."
|
||||
)
|
||||
return self.swift.mainContext.fetchObjectIDs(from, fetchClauses)
|
||||
return self.bridgeToSwift.mainContext.fetchObjectIDs(from, fetchClauses)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -201,6 +201,6 @@ public extension CSDataStack {
|
||||
NSThread.isMainThread(),
|
||||
"Attempted to delete from a \(typeName(self)) outside the main thread."
|
||||
)
|
||||
return self.swift.mainContext.deleteAll(from, deleteClauses)
|
||||
return self.bridgeToSwift.mainContext.deleteAll(from, deleteClauses)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,9 +38,9 @@ public extension CSDataStack {
|
||||
@objc
|
||||
public func beginAsynchronous(closure: (transaction: CSAsynchronousDataTransaction) -> Void) {
|
||||
|
||||
return self.swift.beginAsynchronous { (transaction) in
|
||||
return self.bridgeToSwift.beginAsynchronous { (transaction) in
|
||||
|
||||
closure(transaction: transaction.objc)
|
||||
closure(transaction: transaction.bridgeToObjectiveC)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,9 +55,9 @@ public extension CSDataStack {
|
||||
|
||||
return bridge {
|
||||
|
||||
self.swift.beginSynchronous { (transaction) in
|
||||
self.bridgeToSwift.beginSynchronous { (transaction) in
|
||||
|
||||
closure(transaction: transaction.objc)
|
||||
closure(transaction: transaction.bridgeToObjectiveC)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -74,7 +74,7 @@ public extension CSDataStack {
|
||||
|
||||
return bridge {
|
||||
|
||||
self.swift.beginUnsafe()
|
||||
self.bridgeToSwift.beginUnsafe()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ public extension CSDataStack {
|
||||
|
||||
return bridge {
|
||||
|
||||
self.swift.beginUnsafe(supportsUndo: supportsUndo)
|
||||
self.bridgeToSwift.beginUnsafe(supportsUndo: supportsUndo)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,6 +100,6 @@ public extension CSDataStack {
|
||||
@objc
|
||||
public func refreshAllObjectsAsFaults() {
|
||||
|
||||
self.swift.refreshAllObjectsAsFaults()
|
||||
self.bridgeToSwift.refreshAllObjectsAsFaults()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ import CoreData
|
||||
The `CSDataStack` serves as the Objective-C bridging type for `DataStack`.
|
||||
*/
|
||||
@objc
|
||||
public final class CSDataStack: NSObject, CoreStoreBridge {
|
||||
public final class CSDataStack: NSObject, CoreStoreObjectiveCType {
|
||||
|
||||
/**
|
||||
Initializes a `CSDataStack` with default settings. CoreStore searches for <CFBundleName>.xcdatamodeld from the main `NSBundle` and loads an `NSManagedObjectModel` from it. An assertion is raised if the model could not be found.
|
||||
@@ -122,7 +122,7 @@ public final class CSDataStack: NSObject, CoreStoreBridge {
|
||||
@objc
|
||||
public var modelVersion: String {
|
||||
|
||||
return self.swift.modelVersion
|
||||
return self.bridgeToSwift.modelVersion
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -131,7 +131,7 @@ public final class CSDataStack: NSObject, CoreStoreBridge {
|
||||
@objc
|
||||
public var entityClassesByName: [String: NSManagedObject.Type] {
|
||||
|
||||
return self.swift.entityTypesByName
|
||||
return self.bridgeToSwift.entityTypesByName
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -142,7 +142,7 @@ public final class CSDataStack: NSObject, CoreStoreBridge {
|
||||
@objc
|
||||
public func entityClassWithName(name: String) -> NSManagedObject.Type? {
|
||||
|
||||
return self.swift.entityTypesByName[name]
|
||||
return self.bridgeToSwift.entityTypesByName[name]
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -151,7 +151,7 @@ public final class CSDataStack: NSObject, CoreStoreBridge {
|
||||
@objc
|
||||
public func entityDescriptionForClass(type: NSManagedObject.Type) -> NSEntityDescription? {
|
||||
|
||||
return self.swift.entityDescriptionForType(type)
|
||||
return self.bridgeToSwift.entityDescriptionForType(type)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -167,7 +167,7 @@ public final class CSDataStack: NSObject, CoreStoreBridge {
|
||||
|
||||
return try bridge {
|
||||
|
||||
try self.swift.addStorageAndWait(InMemoryStore)
|
||||
try self.bridgeToSwift.addStorageAndWait(InMemoryStore)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -184,7 +184,7 @@ public final class CSDataStack: NSObject, CoreStoreBridge {
|
||||
|
||||
return try bridge {
|
||||
|
||||
return try self.swift.addStorageAndWait(SQLiteStore)
|
||||
return try self.bridgeToSwift.addStorageAndWait(SQLiteStore)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -205,7 +205,7 @@ public final class CSDataStack: NSObject, CoreStoreBridge {
|
||||
|
||||
return try bridge {
|
||||
|
||||
return try self.swift.addStorageAndWait(storage.swift)
|
||||
return try self.bridgeToSwift.addStorageAndWait(storage.bridgeToSwift)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -226,7 +226,7 @@ public final class CSDataStack: NSObject, CoreStoreBridge {
|
||||
|
||||
return try bridge {
|
||||
|
||||
return try self.swift.addStorageAndWait(storage.swift)
|
||||
return try self.bridgeToSwift.addStorageAndWait(storage.bridgeToSwift)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -235,7 +235,7 @@ public final class CSDataStack: NSObject, CoreStoreBridge {
|
||||
|
||||
public override var hash: Int {
|
||||
|
||||
return ObjectIdentifier(self.swift).hashValue
|
||||
return ObjectIdentifier(self.bridgeToSwift).hashValue
|
||||
}
|
||||
|
||||
public override func isEqual(object: AnyObject?) -> Bool {
|
||||
@@ -244,17 +244,17 @@ public final class CSDataStack: NSObject, CoreStoreBridge {
|
||||
|
||||
return false
|
||||
}
|
||||
return self.swift === object.swift
|
||||
return self.bridgeToSwift === object.bridgeToSwift
|
||||
}
|
||||
|
||||
|
||||
// MARK: CoreStoreBridge
|
||||
// MARK: CoreStoreObjectiveCType
|
||||
|
||||
internal let swift: DataStack
|
||||
public let bridgeToSwift: DataStack
|
||||
|
||||
internal init(_ swiftObject: DataStack) {
|
||||
public init(_ swiftValue: DataStack) {
|
||||
|
||||
self.swift = swiftObject
|
||||
self.bridgeToSwift = swiftValue
|
||||
super.init()
|
||||
}
|
||||
}
|
||||
@@ -262,9 +262,9 @@ public final class CSDataStack: NSObject, CoreStoreBridge {
|
||||
|
||||
// MARK: - DataStack
|
||||
|
||||
extension DataStack: CoreStoreBridgeable {
|
||||
extension DataStack: CoreStoreSwiftType {
|
||||
|
||||
// MARK: CoreStoreBridgeable
|
||||
// MARK: CoreStoreSwiftType
|
||||
|
||||
internal typealias ObjCType = CSDataStack
|
||||
public typealias ObjectiveCType = CSDataStack
|
||||
}
|
||||
|
||||
@@ -32,20 +32,147 @@ import CoreData
|
||||
/**
|
||||
The `CSError` provides a facade for global CoreStore error declarations.
|
||||
*/
|
||||
public final class CSError: NSObject {
|
||||
@objc
|
||||
public final class CSError: NSError, CoreStoreObjectiveCType {
|
||||
|
||||
/**
|
||||
The `NSError` error domain for `CSCoreStore`.
|
||||
*/
|
||||
@objc
|
||||
public static let domain = CoreStoreErrorDomain
|
||||
public static let errorDomain = CoreStoreErrorDomain
|
||||
|
||||
|
||||
// MARK: Private
|
||||
// MARK: NSObject
|
||||
|
||||
private override init() {
|
||||
public override var hash: Int {
|
||||
|
||||
fatalError()
|
||||
return self.bridgeToSwift.hashValue
|
||||
}
|
||||
|
||||
public override func isEqual(object: AnyObject?) -> Bool {
|
||||
|
||||
guard let object = object as? CSError else {
|
||||
|
||||
return false
|
||||
}
|
||||
return self.bridgeToSwift == object.bridgeToSwift
|
||||
}
|
||||
|
||||
|
||||
// MARK: CoreStoreObjectiveCType
|
||||
|
||||
private var swiftError: CoreStoreError?
|
||||
|
||||
public var bridgeToSwift: CoreStoreError {
|
||||
|
||||
if let swift = self.swiftError {
|
||||
|
||||
return swift
|
||||
}
|
||||
|
||||
func createSwiftObject(error: CSError) -> CoreStoreError {
|
||||
|
||||
guard error.domain == CoreStoreErrorDomain else {
|
||||
|
||||
return .InternalError(NSError: self)
|
||||
}
|
||||
|
||||
guard let code = CoreStoreErrorCode(rawValue: error.code) else {
|
||||
|
||||
return .Unknown
|
||||
}
|
||||
|
||||
let info = error.userInfo
|
||||
switch code {
|
||||
|
||||
case .UnknownError:
|
||||
return .Unknown
|
||||
|
||||
case .DifferentPersistentStoreExistsAtURL:
|
||||
guard case let existingPersistentStoreURL as NSURL = info["existingPersistentStoreURL"] else {
|
||||
|
||||
return .Unknown
|
||||
}
|
||||
return .DifferentStorageExistsAtURL(existingPersistentStoreURL: existingPersistentStoreURL)
|
||||
|
||||
case .MappingModelNotFound:
|
||||
guard let localStoreURL = info["localStoreURL"] as? NSURL,
|
||||
let targetModel = info["targetModel"] as? NSManagedObjectModel,
|
||||
let targetModelVersion = info["targetModelVersion"] as? String else {
|
||||
|
||||
return .Unknown
|
||||
}
|
||||
return .MappingModelNotFound(localStoreURL: localStoreURL, targetModel: targetModel, targetModelVersion: targetModelVersion)
|
||||
|
||||
case .ProgressiveMigrationRequired:
|
||||
guard let localStoreURL = info["localStoreURL"] as? NSURL else {
|
||||
|
||||
return .Unknown
|
||||
}
|
||||
return .ProgressiveMigrationRequired(localStoreURL: localStoreURL)
|
||||
|
||||
case .InternalError:
|
||||
guard case let NSError as NSError = info["NSError"] else {
|
||||
|
||||
return .Unknown
|
||||
}
|
||||
return .InternalError(NSError: NSError)
|
||||
}
|
||||
}
|
||||
|
||||
let swift = createSwiftObject(self)
|
||||
self.swiftError = swift
|
||||
return swift
|
||||
}
|
||||
|
||||
/**
|
||||
Do not call directly!
|
||||
*/
|
||||
public init(_ swiftValue: CoreStoreError) {
|
||||
|
||||
self.swiftError = swiftValue
|
||||
|
||||
let code: CoreStoreErrorCode
|
||||
let info: [NSObject: AnyObject]
|
||||
switch swiftValue {
|
||||
|
||||
case .Unknown:
|
||||
code = .UnknownError
|
||||
info = [:]
|
||||
|
||||
case .DifferentStorageExistsAtURL(let existingPersistentStoreURL):
|
||||
code = .DifferentPersistentStoreExistsAtURL
|
||||
info = [
|
||||
"existingPersistentStoreURL": existingPersistentStoreURL
|
||||
]
|
||||
|
||||
case .MappingModelNotFound(let localStoreURL, let targetModel, let targetModelVersion):
|
||||
code = .MappingModelNotFound
|
||||
info = [
|
||||
"localStoreURL": localStoreURL,
|
||||
"targetModel": targetModel,
|
||||
"targetModelVersion": targetModelVersion
|
||||
]
|
||||
|
||||
case .ProgressiveMigrationRequired(let localStoreURL):
|
||||
code = .ProgressiveMigrationRequired
|
||||
info = [
|
||||
"localStoreURL": localStoreURL
|
||||
]
|
||||
|
||||
case .InternalError(let NSError):
|
||||
code = .InternalError
|
||||
info = [
|
||||
"NSError": NSError
|
||||
]
|
||||
}
|
||||
|
||||
super.init(domain: CoreStoreErrorDomain, code: code.rawValue, userInfo: info)
|
||||
}
|
||||
|
||||
public required init?(coder aDecoder: NSCoder) {
|
||||
|
||||
super.init(coder: aDecoder)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,112 +212,40 @@ public enum CSErrorCode: Int {
|
||||
}
|
||||
|
||||
|
||||
// MARK: - CoreStoreError
|
||||
|
||||
extension CoreStoreError: CoreStoreSwiftType {
|
||||
|
||||
// MARK: CoreStoreSwiftType
|
||||
|
||||
public var bridgeToObjectiveC: CSError {
|
||||
|
||||
return CSError(self)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: Internal
|
||||
|
||||
internal extension ErrorType {
|
||||
|
||||
internal var swift: CoreStoreError {
|
||||
internal var bridgeToSwift: CoreStoreError {
|
||||
|
||||
if case let error as CoreStoreError = self {
|
||||
switch self {
|
||||
|
||||
return error
|
||||
}
|
||||
|
||||
guard let error = (self as Any) as? NSError else {
|
||||
|
||||
return .Unknown
|
||||
}
|
||||
|
||||
guard error.domain == CoreStoreErrorDomain else {
|
||||
|
||||
return .InternalError(NSError: error)
|
||||
}
|
||||
|
||||
guard let code = CoreStoreErrorCode(rawValue: error.code) else {
|
||||
|
||||
return .Unknown
|
||||
}
|
||||
|
||||
let info = error.userInfo
|
||||
switch code {
|
||||
|
||||
case .UnknownError:
|
||||
return .Unknown
|
||||
|
||||
case .DifferentPersistentStoreExistsAtURL:
|
||||
guard case let existingPersistentStoreURL as NSURL = info["existingPersistentStoreURL"] else {
|
||||
|
||||
return .Unknown
|
||||
}
|
||||
return .DifferentStorageExistsAtURL(existingPersistentStoreURL: existingPersistentStoreURL)
|
||||
|
||||
case .MappingModelNotFound:
|
||||
guard let localStoreURL = info["localStoreURL"] as? NSURL,
|
||||
let targetModel = info["targetModel"] as? NSManagedObjectModel,
|
||||
let targetModelVersion = info["targetModelVersion"] as? String else {
|
||||
|
||||
return .Unknown
|
||||
}
|
||||
return .MappingModelNotFound(localStoreURL: localStoreURL, targetModel: targetModel, targetModelVersion: targetModelVersion)
|
||||
|
||||
case .ProgressiveMigrationRequired:
|
||||
guard let localStoreURL = info["localStoreURL"] as? NSURL else {
|
||||
|
||||
return .Unknown
|
||||
}
|
||||
return .ProgressiveMigrationRequired(localStoreURL: localStoreURL)
|
||||
|
||||
case .InternalError:
|
||||
guard case let NSError as NSError = info["NSError"] else {
|
||||
|
||||
return .Unknown
|
||||
}
|
||||
return .InternalError(NSError: NSError)
|
||||
case let error as CoreStoreError: return error
|
||||
case let error as CSError: return error.bridgeToSwift
|
||||
default: return .Unknown
|
||||
}
|
||||
}
|
||||
|
||||
internal var objc: NSError {
|
||||
internal var bridgeToObjectiveC: NSError {
|
||||
|
||||
guard let error = self as? CoreStoreError else {
|
||||
switch self {
|
||||
|
||||
return ((self as Any) as? NSError) ?? self as NSError
|
||||
case let error as CoreStoreError: return error.bridgeToObjectiveC
|
||||
case let error as CSError: return error
|
||||
default: return self as NSError
|
||||
}
|
||||
|
||||
let code: CoreStoreErrorCode
|
||||
let info: [NSObject: AnyObject]
|
||||
switch error {
|
||||
|
||||
case .Unknown:
|
||||
code = .UnknownError
|
||||
info = [:]
|
||||
|
||||
case .DifferentStorageExistsAtURL(let existingPersistentStoreURL):
|
||||
code = .DifferentPersistentStoreExistsAtURL
|
||||
info = [
|
||||
"existingPersistentStoreURL": existingPersistentStoreURL
|
||||
]
|
||||
|
||||
case .MappingModelNotFound(let localStoreURL, let targetModel, let targetModelVersion):
|
||||
code = .MappingModelNotFound
|
||||
info = [
|
||||
"localStoreURL": localStoreURL,
|
||||
"targetModel": targetModel,
|
||||
"targetModelVersion": targetModelVersion
|
||||
]
|
||||
|
||||
case .ProgressiveMigrationRequired(let localStoreURL):
|
||||
code = .ProgressiveMigrationRequired
|
||||
info = [
|
||||
"localStoreURL": localStoreURL
|
||||
]
|
||||
|
||||
case .InternalError(let NSError):
|
||||
code = .InternalError
|
||||
info = [
|
||||
"NSError": NSError
|
||||
]
|
||||
}
|
||||
|
||||
return NSError(domain: CoreStoreErrorDomain, code: code.rawValue, userInfo: info)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ import CoreData
|
||||
The `CSFrom` serves as the Objective-C bridging type for `From`.
|
||||
*/
|
||||
@objc
|
||||
public final class CSFrom: NSObject, CoreStoreBridge {
|
||||
public final class CSFrom: NSObject, CoreStoreObjectiveCType {
|
||||
|
||||
/**
|
||||
Initializes a `CSFrom` clause with the specified entity class.
|
||||
@@ -106,13 +106,13 @@ public final class CSFrom: NSObject, CoreStoreBridge {
|
||||
}
|
||||
|
||||
|
||||
// MARK: CoreStoreBridge
|
||||
// MARK: CoreStoreObjectiveCType
|
||||
|
||||
internal let swift: From<NSManagedObject>
|
||||
public let bridgeToSwift: From<NSManagedObject>
|
||||
|
||||
internal init<T: NSManagedObject>(_ swiftObject: From<T>) {
|
||||
public init<T: NSManagedObject>(_ swiftValue: From<T>) {
|
||||
|
||||
self.swift = swiftObject.upcast()
|
||||
self.bridgeToSwift = swiftValue.upcast()
|
||||
super.init()
|
||||
}
|
||||
}
|
||||
@@ -120,11 +120,11 @@ public final class CSFrom: NSObject, CoreStoreBridge {
|
||||
|
||||
// MARK: - From
|
||||
|
||||
extension From: CoreStoreBridgeable {
|
||||
extension From: CoreStoreSwiftType {
|
||||
|
||||
// MARK: CoreStoreBridgeable
|
||||
// MARK: CoreStoreSwiftType
|
||||
|
||||
internal var objc: CSFrom {
|
||||
public var bridgeToObjectiveC: CSFrom {
|
||||
|
||||
return CSFrom(self)
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ import CoreData
|
||||
The `CSGroupBy` serves as the Objective-C bridging type for `GroupBy`.
|
||||
*/
|
||||
@objc
|
||||
public final class CSGroupBy: NSObject, CSQueryClause, CoreStoreBridge {
|
||||
public final class CSGroupBy: NSObject, CSQueryClause, CoreStoreObjectiveCType {
|
||||
|
||||
/**
|
||||
Initializes a `CSGroupBy` clause with a list of key path strings
|
||||
@@ -52,7 +52,7 @@ public final class CSGroupBy: NSObject, CSQueryClause, CoreStoreBridge {
|
||||
|
||||
public override var hash: Int {
|
||||
|
||||
return self.swift.hashValue
|
||||
return self.bridgeToSwift.hashValue
|
||||
}
|
||||
|
||||
public override func isEqual(object: AnyObject?) -> Bool {
|
||||
@@ -61,7 +61,7 @@ public final class CSGroupBy: NSObject, CSQueryClause, CoreStoreBridge {
|
||||
|
||||
return false
|
||||
}
|
||||
return self.swift == object.swift
|
||||
return self.bridgeToSwift == object.bridgeToSwift
|
||||
}
|
||||
|
||||
|
||||
@@ -70,17 +70,17 @@ public final class CSGroupBy: NSObject, CSQueryClause, CoreStoreBridge {
|
||||
@objc
|
||||
public func applyToFetchRequest(fetchRequest: NSFetchRequest) {
|
||||
|
||||
self.swift.applyToFetchRequest(fetchRequest)
|
||||
self.bridgeToSwift.applyToFetchRequest(fetchRequest)
|
||||
}
|
||||
|
||||
|
||||
// MARK: CoreStoreBridge
|
||||
// MARK: CoreStoreObjectiveCType
|
||||
|
||||
internal let swift: GroupBy
|
||||
public let bridgeToSwift: GroupBy
|
||||
|
||||
internal init(_ swiftObject: GroupBy) {
|
||||
public init(_ swiftValue: GroupBy) {
|
||||
|
||||
self.swift = swiftObject
|
||||
self.bridgeToSwift = swiftValue
|
||||
super.init()
|
||||
}
|
||||
}
|
||||
@@ -88,9 +88,9 @@ public final class CSGroupBy: NSObject, CSQueryClause, CoreStoreBridge {
|
||||
|
||||
// MARK: - GroupBy
|
||||
|
||||
extension GroupBy: CoreStoreBridgeable {
|
||||
extension GroupBy: CoreStoreSwiftType {
|
||||
|
||||
// MARK: CoreStoreBridgeable
|
||||
// MARK: CoreStoreSwiftType
|
||||
|
||||
internal typealias ObjCType = CSGroupBy
|
||||
public typealias ObjectiveCType = CSGroupBy
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ import CoreData
|
||||
The `CSInMemoryStore` serves as the Objective-C bridging type for `InMemoryStore`.
|
||||
*/
|
||||
@objc
|
||||
public final class CSInMemoryStore: NSObject, CSStorageInterface, CoreStoreBridge {
|
||||
public final class CSInMemoryStore: NSObject, CSStorageInterface, CoreStoreObjectiveCType {
|
||||
|
||||
/**
|
||||
Initializes a `CSInMemoryStore` for the specified configuration
|
||||
@@ -70,7 +70,7 @@ public final class CSInMemoryStore: NSObject, CSStorageInterface, CoreStoreBridg
|
||||
@objc
|
||||
public var configuration: String? {
|
||||
|
||||
return self.swift.configuration
|
||||
return self.bridgeToSwift.configuration
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -79,7 +79,7 @@ public final class CSInMemoryStore: NSObject, CSStorageInterface, CoreStoreBridg
|
||||
@objc
|
||||
public var storeOptions: [String: AnyObject]? {
|
||||
|
||||
return self.swift.storeOptions
|
||||
return self.bridgeToSwift.storeOptions
|
||||
}
|
||||
|
||||
|
||||
@@ -87,7 +87,7 @@ public final class CSInMemoryStore: NSObject, CSStorageInterface, CoreStoreBridg
|
||||
|
||||
public override var hash: Int {
|
||||
|
||||
return ObjectIdentifier(self.swift).hashValue
|
||||
return ObjectIdentifier(self.bridgeToSwift).hashValue
|
||||
}
|
||||
|
||||
public override func isEqual(object: AnyObject?) -> Bool {
|
||||
@@ -96,17 +96,17 @@ public final class CSInMemoryStore: NSObject, CSStorageInterface, CoreStoreBridg
|
||||
|
||||
return false
|
||||
}
|
||||
return self.swift === object.swift
|
||||
return self.bridgeToSwift === object.bridgeToSwift
|
||||
}
|
||||
|
||||
|
||||
// MARK: CoreStoreBridge
|
||||
// MARK: CoreStoreObjectiveCType
|
||||
|
||||
internal let swift: InMemoryStore
|
||||
public let bridgeToSwift: InMemoryStore
|
||||
|
||||
public required init(_ swiftObject: InMemoryStore) {
|
||||
public required init(_ swiftValue: InMemoryStore) {
|
||||
|
||||
self.swift = swiftObject
|
||||
self.bridgeToSwift = swiftValue
|
||||
super.init()
|
||||
}
|
||||
}
|
||||
@@ -114,9 +114,9 @@ public final class CSInMemoryStore: NSObject, CSStorageInterface, CoreStoreBridg
|
||||
|
||||
// MARK: - InMemoryStore
|
||||
|
||||
extension InMemoryStore: CoreStoreBridgeable {
|
||||
extension InMemoryStore: CoreStoreSwiftType {
|
||||
|
||||
// MARK: CoreStoreBridgeable
|
||||
// MARK: CoreStoreSwiftType
|
||||
|
||||
internal typealias ObjCType = CSInMemoryStore
|
||||
public typealias ObjectiveCType = CSInMemoryStore
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ import CoreData
|
||||
The `CSInto` serves as the Objective-C bridging type for `Into<T>`.
|
||||
*/
|
||||
@objc
|
||||
public final class CSInto: NSObject, CoreStoreBridge {
|
||||
public final class CSInto: NSObject, CoreStoreObjectiveCType {
|
||||
|
||||
/**
|
||||
Initializes a `CSInto` clause with the specified entity class.
|
||||
@@ -69,7 +69,7 @@ public final class CSInto: NSObject, CoreStoreBridge {
|
||||
|
||||
public override var hash: Int {
|
||||
|
||||
return self.swift.hashValue
|
||||
return self.bridgeToSwift.hashValue
|
||||
}
|
||||
|
||||
public override func isEqual(object: AnyObject?) -> Bool {
|
||||
@@ -78,17 +78,17 @@ public final class CSInto: NSObject, CoreStoreBridge {
|
||||
|
||||
return false
|
||||
}
|
||||
return self.swift == object.swift
|
||||
return self.bridgeToSwift == object.bridgeToSwift
|
||||
}
|
||||
|
||||
|
||||
// MARK: CoreStoreBridge
|
||||
// MARK: CoreStoreObjectiveCType
|
||||
|
||||
internal let swift: Into<NSManagedObject>
|
||||
public let bridgeToSwift: Into<NSManagedObject>
|
||||
|
||||
public required init<T: NSManagedObject>(_ swiftObject: Into<T>) {
|
||||
public required init<T: NSManagedObject>(_ swiftValue: Into<T>) {
|
||||
|
||||
self.swift = swiftObject.upcast()
|
||||
self.bridgeToSwift = swiftValue.upcast()
|
||||
super.init()
|
||||
}
|
||||
}
|
||||
@@ -96,11 +96,11 @@ public final class CSInto: NSObject, CoreStoreBridge {
|
||||
|
||||
// MARK: - Into
|
||||
|
||||
extension Into: CoreStoreBridgeable {
|
||||
extension Into: CoreStoreSwiftType {
|
||||
|
||||
// MARK: CoreStoreBridgeable
|
||||
// MARK: CoreStoreSwiftType
|
||||
|
||||
internal var objc: CSInto {
|
||||
public var bridgeToObjectiveC: CSInto {
|
||||
|
||||
return CSInto(self)
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ import CoreData
|
||||
*/
|
||||
@available(OSX, unavailable)
|
||||
@objc
|
||||
public final class CSListMonitor: NSObject, CoreStoreBridge {
|
||||
public final class CSListMonitor: NSObject, CoreStoreObjectiveCType {
|
||||
|
||||
// MARK: Public (Accessors)
|
||||
|
||||
@@ -47,7 +47,7 @@ public final class CSListMonitor: NSObject, CoreStoreBridge {
|
||||
@objc
|
||||
public subscript(index: Int) -> NSManagedObject {
|
||||
|
||||
return self.swift[index]
|
||||
return self.bridgeToSwift[index]
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -59,7 +59,7 @@ public final class CSListMonitor: NSObject, CoreStoreBridge {
|
||||
@objc
|
||||
public func objectAtSafeIndex(index: Int) -> NSManagedObject? {
|
||||
|
||||
return self.swift[safeIndex: index]
|
||||
return self.bridgeToSwift[safeIndex: index]
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -72,7 +72,7 @@ public final class CSListMonitor: NSObject, CoreStoreBridge {
|
||||
@objc
|
||||
public func objectAtSectionIndex(sectionIndex: Int, itemIndex: Int) -> NSManagedObject {
|
||||
|
||||
return self.swift[sectionIndex, itemIndex]
|
||||
return self.bridgeToSwift[sectionIndex, itemIndex]
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -85,7 +85,7 @@ public final class CSListMonitor: NSObject, CoreStoreBridge {
|
||||
@objc
|
||||
public func objectAtSafeSectionIndex(sectionIndex: Int, safeItemIndex itemIndex: Int) -> NSManagedObject? {
|
||||
|
||||
return self.swift[safeSectionIndex: sectionIndex, safeItemIndex: itemIndex]
|
||||
return self.bridgeToSwift[safeSectionIndex: sectionIndex, safeItemIndex: itemIndex]
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -97,7 +97,7 @@ public final class CSListMonitor: NSObject, CoreStoreBridge {
|
||||
@objc
|
||||
public func objectAtIndexPath(indexPath: NSIndexPath) -> NSManagedObject {
|
||||
|
||||
return self.swift[indexPath]
|
||||
return self.bridgeToSwift[indexPath]
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -109,7 +109,7 @@ public final class CSListMonitor: NSObject, CoreStoreBridge {
|
||||
@objc
|
||||
public func objectAtSafeIndexPath(indexPath: NSIndexPath) -> NSManagedObject? {
|
||||
|
||||
return self.swift[safeIndexPath: indexPath]
|
||||
return self.bridgeToSwift[safeIndexPath: indexPath]
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -121,7 +121,7 @@ public final class CSListMonitor: NSObject, CoreStoreBridge {
|
||||
@warn_unused_result
|
||||
public func hasObjects() -> Bool {
|
||||
|
||||
return self.swift.hasObjects()
|
||||
return self.bridgeToSwift.hasObjects()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -134,7 +134,7 @@ public final class CSListMonitor: NSObject, CoreStoreBridge {
|
||||
@warn_unused_result
|
||||
public func hasObjectsInSection(section: Int) -> Bool {
|
||||
|
||||
return self.swift.hasObjectsInSection(section)
|
||||
return self.bridgeToSwift.hasObjectsInSection(section)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -146,7 +146,7 @@ public final class CSListMonitor: NSObject, CoreStoreBridge {
|
||||
@warn_unused_result
|
||||
public func objectsInAllSections() -> [NSManagedObject] {
|
||||
|
||||
return self.swift.objectsInAllSections()
|
||||
return self.bridgeToSwift.objectsInAllSections()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -159,7 +159,7 @@ public final class CSListMonitor: NSObject, CoreStoreBridge {
|
||||
@warn_unused_result
|
||||
public func objectsInSection(section: Int) -> [NSManagedObject] {
|
||||
|
||||
return self.swift.objectsInSection(section)
|
||||
return self.bridgeToSwift.objectsInSection(section)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -172,7 +172,7 @@ public final class CSListMonitor: NSObject, CoreStoreBridge {
|
||||
@warn_unused_result
|
||||
public func objectsInSafeSection(safeSectionIndex section: Int) -> [NSManagedObject]? {
|
||||
|
||||
return self.swift.objectsInSection(safeSectionIndex: section)
|
||||
return self.bridgeToSwift.objectsInSection(safeSectionIndex: section)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -184,7 +184,7 @@ public final class CSListMonitor: NSObject, CoreStoreBridge {
|
||||
@warn_unused_result
|
||||
public func numberOfSections() -> Int {
|
||||
|
||||
return self.swift.numberOfSections()
|
||||
return self.bridgeToSwift.numberOfSections()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -196,7 +196,7 @@ public final class CSListMonitor: NSObject, CoreStoreBridge {
|
||||
@warn_unused_result
|
||||
public func numberOfObjects() -> Int {
|
||||
|
||||
return self.swift.numberOfObjects()
|
||||
return self.bridgeToSwift.numberOfObjects()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -209,7 +209,7 @@ public final class CSListMonitor: NSObject, CoreStoreBridge {
|
||||
@warn_unused_result
|
||||
public func numberOfObjectsInSection(section: Int) -> Int {
|
||||
|
||||
return self.swift.numberOfObjectsInSection(section)
|
||||
return self.bridgeToSwift.numberOfObjectsInSection(section)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -222,7 +222,7 @@ public final class CSListMonitor: NSObject, CoreStoreBridge {
|
||||
@warn_unused_result
|
||||
public func numberOfObjectsInSafeSection(safeSectionIndex section: Int) -> NSNumber? {
|
||||
|
||||
return self.swift.numberOfObjectsInSection(safeSectionIndex: section)
|
||||
return self.bridgeToSwift.numberOfObjectsInSection(safeSectionIndex: section)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -235,7 +235,7 @@ public final class CSListMonitor: NSObject, CoreStoreBridge {
|
||||
@warn_unused_result
|
||||
public func sectionInfoAtIndex(section: Int) -> NSFetchedResultsSectionInfo {
|
||||
|
||||
return self.swift.sectionInfoAtIndex(section)
|
||||
return self.bridgeToSwift.sectionInfoAtIndex(section)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -248,7 +248,7 @@ public final class CSListMonitor: NSObject, CoreStoreBridge {
|
||||
@warn_unused_result
|
||||
public func sectionInfoAtSafeSectionIndex(safeSectionIndex section: Int) -> NSFetchedResultsSectionInfo? {
|
||||
|
||||
return self.swift.sectionInfoAtIndex(safeSectionIndex: section)
|
||||
return self.bridgeToSwift.sectionInfoAtIndex(safeSectionIndex: section)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -260,7 +260,7 @@ public final class CSListMonitor: NSObject, CoreStoreBridge {
|
||||
@warn_unused_result
|
||||
public func sections() -> [NSFetchedResultsSectionInfo] {
|
||||
|
||||
return self.swift.sections()
|
||||
return self.bridgeToSwift.sections()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -274,7 +274,7 @@ public final class CSListMonitor: NSObject, CoreStoreBridge {
|
||||
@warn_unused_result
|
||||
public func targetSectionForSectionIndexTitle(title title: String, index: Int) -> Int {
|
||||
|
||||
return self.swift.targetSectionForSectionIndex(title: title, index: index)
|
||||
return self.bridgeToSwift.targetSectionForSectionIndex(title: title, index: index)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -286,7 +286,7 @@ public final class CSListMonitor: NSObject, CoreStoreBridge {
|
||||
@warn_unused_result
|
||||
public func sectionIndexTitles() -> [String] {
|
||||
|
||||
return self.swift.sectionIndexTitles()
|
||||
return self.bridgeToSwift.sectionIndexTitles()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -299,7 +299,7 @@ public final class CSListMonitor: NSObject, CoreStoreBridge {
|
||||
@warn_unused_result
|
||||
public func indexOf(object: NSManagedObject) -> NSNumber? {
|
||||
|
||||
return self.swift.indexOf(object)
|
||||
return self.bridgeToSwift.indexOf(object)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -312,7 +312,7 @@ public final class CSListMonitor: NSObject, CoreStoreBridge {
|
||||
@warn_unused_result
|
||||
public func indexPathOf(object: NSManagedObject) -> NSIndexPath? {
|
||||
|
||||
return self.swift.indexPathOf(object)
|
||||
return self.bridgeToSwift.indexPathOf(object)
|
||||
}
|
||||
|
||||
|
||||
@@ -332,25 +332,25 @@ public final class CSListMonitor: NSObject, CoreStoreBridge {
|
||||
@objc
|
||||
public func addListObserver(observer: CSListObserver) {
|
||||
|
||||
let swift = self.swift
|
||||
let swift = self.bridgeToSwift
|
||||
swift.unregisterObserver(observer)
|
||||
swift.registerObserver(
|
||||
observer,
|
||||
willChange: { (observer, monitor) in
|
||||
|
||||
observer.listMonitorWillChange?(monitor.objc)
|
||||
observer.listMonitorWillChange?(monitor.bridgeToObjectiveC)
|
||||
},
|
||||
didChange: { (observer, monitor) in
|
||||
|
||||
observer.listMonitorDidChange?(monitor.objc)
|
||||
observer.listMonitorDidChange?(monitor.bridgeToObjectiveC)
|
||||
},
|
||||
willRefetch: { (observer, monitor) in
|
||||
|
||||
observer.listMonitorWillRefetch?(monitor.objc)
|
||||
observer.listMonitorWillRefetch?(monitor.bridgeToObjectiveC)
|
||||
},
|
||||
didRefetch: { (observer, monitor) in
|
||||
|
||||
observer.listMonitorDidRefetch?(monitor.objc)
|
||||
observer.listMonitorDidRefetch?(monitor.bridgeToObjectiveC)
|
||||
}
|
||||
)
|
||||
}
|
||||
@@ -368,44 +368,44 @@ public final class CSListMonitor: NSObject, CoreStoreBridge {
|
||||
*/
|
||||
public func addListObjectObserver(observer: CSListObjectObserver) {
|
||||
|
||||
let swift = self.swift
|
||||
let swift = self.bridgeToSwift
|
||||
swift.unregisterObserver(observer)
|
||||
swift.registerObserver(
|
||||
observer,
|
||||
willChange: { (observer, monitor) in
|
||||
|
||||
observer.listMonitorWillChange?(monitor.objc)
|
||||
observer.listMonitorWillChange?(monitor.bridgeToObjectiveC)
|
||||
},
|
||||
didChange: { (observer, monitor) in
|
||||
|
||||
observer.listMonitorDidChange?(monitor.objc)
|
||||
observer.listMonitorDidChange?(monitor.bridgeToObjectiveC)
|
||||
},
|
||||
willRefetch: { (observer, monitor) in
|
||||
|
||||
observer.listMonitorWillRefetch?(monitor.objc)
|
||||
observer.listMonitorWillRefetch?(monitor.bridgeToObjectiveC)
|
||||
},
|
||||
didRefetch: { (observer, monitor) in
|
||||
|
||||
observer.listMonitorDidRefetch?(monitor.objc)
|
||||
observer.listMonitorDidRefetch?(monitor.bridgeToObjectiveC)
|
||||
}
|
||||
)
|
||||
swift.registerObserver(
|
||||
observer,
|
||||
didInsertObject: { (observer, monitor, object, toIndexPath) in
|
||||
|
||||
observer.listMonitor?(monitor.objc, didInsertObject: object, toIndexPath: toIndexPath)
|
||||
observer.listMonitor?(monitor.bridgeToObjectiveC, didInsertObject: object, toIndexPath: toIndexPath)
|
||||
},
|
||||
didDeleteObject: { (observer, monitor, object, fromIndexPath) in
|
||||
|
||||
observer.listMonitor?(monitor.objc, didDeleteObject: object, fromIndexPath: fromIndexPath)
|
||||
observer.listMonitor?(monitor.bridgeToObjectiveC, didDeleteObject: object, fromIndexPath: fromIndexPath)
|
||||
},
|
||||
didUpdateObject: { (observer, monitor, object, atIndexPath) in
|
||||
|
||||
observer.listMonitor?(monitor.objc, didUpdateObject: object, atIndexPath: atIndexPath)
|
||||
observer.listMonitor?(monitor.bridgeToObjectiveC, didUpdateObject: object, atIndexPath: atIndexPath)
|
||||
},
|
||||
didMoveObject: { (observer, monitor, object, fromIndexPath, toIndexPath) in
|
||||
|
||||
observer.listMonitor?(monitor.objc, didMoveObject: object, fromIndexPath: fromIndexPath, toIndexPath: toIndexPath)
|
||||
observer.listMonitor?(monitor.bridgeToObjectiveC, didMoveObject: object, fromIndexPath: fromIndexPath, toIndexPath: toIndexPath)
|
||||
}
|
||||
)
|
||||
}
|
||||
@@ -424,55 +424,55 @@ public final class CSListMonitor: NSObject, CoreStoreBridge {
|
||||
@objc
|
||||
public func addListSectionObserver(observer: CSListSectionObserver) {
|
||||
|
||||
let swift = self.swift
|
||||
let swift = self.bridgeToSwift
|
||||
swift.unregisterObserver(observer)
|
||||
swift.registerObserver(
|
||||
observer,
|
||||
willChange: { (observer, monitor) in
|
||||
|
||||
observer.listMonitorWillChange?(monitor.objc)
|
||||
observer.listMonitorWillChange?(monitor.bridgeToObjectiveC)
|
||||
},
|
||||
didChange: { (observer, monitor) in
|
||||
|
||||
observer.listMonitorDidChange?(monitor.objc)
|
||||
observer.listMonitorDidChange?(monitor.bridgeToObjectiveC)
|
||||
},
|
||||
willRefetch: { (observer, monitor) in
|
||||
|
||||
observer.listMonitorWillRefetch?(monitor.objc)
|
||||
observer.listMonitorWillRefetch?(monitor.bridgeToObjectiveC)
|
||||
},
|
||||
didRefetch: { (observer, monitor) in
|
||||
|
||||
observer.listMonitorDidRefetch?(monitor.objc)
|
||||
observer.listMonitorDidRefetch?(monitor.bridgeToObjectiveC)
|
||||
}
|
||||
)
|
||||
swift.registerObserver(
|
||||
observer,
|
||||
didInsertObject: { (observer, monitor, object, toIndexPath) in
|
||||
|
||||
observer.listMonitor?(monitor.objc, didInsertObject: object, toIndexPath: toIndexPath)
|
||||
observer.listMonitor?(monitor.bridgeToObjectiveC, didInsertObject: object, toIndexPath: toIndexPath)
|
||||
},
|
||||
didDeleteObject: { (observer, monitor, object, fromIndexPath) in
|
||||
|
||||
observer.listMonitor?(monitor.objc, didDeleteObject: object, fromIndexPath: fromIndexPath)
|
||||
observer.listMonitor?(monitor.bridgeToObjectiveC, didDeleteObject: object, fromIndexPath: fromIndexPath)
|
||||
},
|
||||
didUpdateObject: { (observer, monitor, object, atIndexPath) in
|
||||
|
||||
observer.listMonitor?(monitor.objc, didUpdateObject: object, atIndexPath: atIndexPath)
|
||||
observer.listMonitor?(monitor.bridgeToObjectiveC, didUpdateObject: object, atIndexPath: atIndexPath)
|
||||
},
|
||||
didMoveObject: { (observer, monitor, object, fromIndexPath, toIndexPath) in
|
||||
|
||||
observer.listMonitor?(monitor.objc, didMoveObject: object, fromIndexPath: fromIndexPath, toIndexPath: toIndexPath)
|
||||
observer.listMonitor?(monitor.bridgeToObjectiveC, didMoveObject: object, fromIndexPath: fromIndexPath, toIndexPath: toIndexPath)
|
||||
}
|
||||
)
|
||||
swift.registerObserver(
|
||||
observer,
|
||||
didInsertSection: { (observer, monitor, sectionInfo, toIndex) in
|
||||
|
||||
observer.listMonitor?(monitor.objc, didInsertSection: sectionInfo, toSectionIndex: toIndex)
|
||||
observer.listMonitor?(monitor.bridgeToObjectiveC, didInsertSection: sectionInfo, toSectionIndex: toIndex)
|
||||
},
|
||||
didDeleteSection: { (observer, monitor, sectionInfo, fromIndex) in
|
||||
|
||||
observer.listMonitor?(monitor.objc, didDeleteSection: sectionInfo, fromSectionIndex: fromIndex)
|
||||
observer.listMonitor?(monitor.bridgeToObjectiveC, didDeleteSection: sectionInfo, fromSectionIndex: fromIndex)
|
||||
}
|
||||
)
|
||||
}
|
||||
@@ -487,7 +487,7 @@ public final class CSListMonitor: NSObject, CoreStoreBridge {
|
||||
@objc
|
||||
public func removeObserver(observer: CSListObserver) {
|
||||
|
||||
self.swift.unregisterObserver(observer)
|
||||
self.bridgeToSwift.unregisterObserver(observer)
|
||||
}
|
||||
|
||||
|
||||
@@ -499,7 +499,7 @@ public final class CSListMonitor: NSObject, CoreStoreBridge {
|
||||
@objc
|
||||
public var isPendingRefetch: Bool {
|
||||
|
||||
return self.swift.isPendingRefetch
|
||||
return self.bridgeToSwift.isPendingRefetch
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -511,7 +511,7 @@ public final class CSListMonitor: NSObject, CoreStoreBridge {
|
||||
*/
|
||||
public func refetch(fetchClauses: [CSFetchClause]) {
|
||||
|
||||
self.swift.refetch { (fetchRequest) in
|
||||
self.bridgeToSwift.refetch { (fetchRequest) in
|
||||
|
||||
fetchClauses.forEach { $0.applyToFetchRequest(fetchRequest) }
|
||||
}
|
||||
@@ -522,7 +522,7 @@ public final class CSListMonitor: NSObject, CoreStoreBridge {
|
||||
|
||||
public override var hash: Int {
|
||||
|
||||
return self.swift.hashValue
|
||||
return self.bridgeToSwift.hashValue
|
||||
}
|
||||
|
||||
public override func isEqual(object: AnyObject?) -> Bool {
|
||||
@@ -531,17 +531,18 @@ public final class CSListMonitor: NSObject, CoreStoreBridge {
|
||||
|
||||
return false
|
||||
}
|
||||
return self.swift == object.swift
|
||||
return self.bridgeToSwift == object.bridgeToSwift
|
||||
}
|
||||
|
||||
|
||||
// MARK: CoreStoreBridge
|
||||
// MARK: CoreStoreObjectiveCType
|
||||
|
||||
internal let swift: ListMonitor<NSManagedObject>
|
||||
public let bridgeToSwift: ListMonitor<NSManagedObject>
|
||||
|
||||
public required init<T: NSManagedObject>(_ swiftObject: ListMonitor<T>) {
|
||||
@nonobjc
|
||||
public required init<T: NSManagedObject>(_ swiftValue: ListMonitor<T>) {
|
||||
|
||||
self.swift = swiftObject.upcast()
|
||||
self.bridgeToSwift = swiftValue.upcast()
|
||||
super.init()
|
||||
}
|
||||
}
|
||||
@@ -549,11 +550,11 @@ public final class CSListMonitor: NSObject, CoreStoreBridge {
|
||||
|
||||
// MARK: - ListMonitor
|
||||
|
||||
extension ListMonitor: CoreStoreBridgeable {
|
||||
extension ListMonitor: CoreStoreSwiftType {
|
||||
|
||||
// MARK: CoreStoreBridgeable
|
||||
// MARK: CoreStoreSwiftType
|
||||
|
||||
internal var objc: CSListMonitor {
|
||||
public var bridgeToObjectiveC: CSListMonitor {
|
||||
|
||||
return CSListMonitor(self)
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ public final class CSSortKey: NSSortDescriptor {
|
||||
The `CSOrderBy` serves as the Objective-C bridging type for `OrderBy`.
|
||||
*/
|
||||
@objc
|
||||
public final class CSOrderBy: NSObject, CSFetchClause, CSQueryClause, CSDeleteClause, CoreStoreBridge {
|
||||
public final class CSOrderBy: NSObject, CSFetchClause, CSQueryClause, CSDeleteClause, CoreStoreObjectiveCType {
|
||||
|
||||
/**
|
||||
Initializes a `CSOrderBy` clause with a list of sort descriptors
|
||||
@@ -87,7 +87,7 @@ public final class CSOrderBy: NSObject, CSFetchClause, CSQueryClause, CSDeleteCl
|
||||
|
||||
public override var hash: Int {
|
||||
|
||||
return self.swift.hashValue
|
||||
return self.bridgeToSwift.hashValue
|
||||
}
|
||||
|
||||
public override func isEqual(object: AnyObject?) -> Bool {
|
||||
@@ -96,7 +96,7 @@ public final class CSOrderBy: NSObject, CSFetchClause, CSQueryClause, CSDeleteCl
|
||||
|
||||
return false
|
||||
}
|
||||
return self.swift == object.swift
|
||||
return self.bridgeToSwift == object.bridgeToSwift
|
||||
}
|
||||
|
||||
|
||||
@@ -105,17 +105,17 @@ public final class CSOrderBy: NSObject, CSFetchClause, CSQueryClause, CSDeleteCl
|
||||
@objc
|
||||
public func applyToFetchRequest(fetchRequest: NSFetchRequest) {
|
||||
|
||||
self.swift.applyToFetchRequest(fetchRequest)
|
||||
self.bridgeToSwift.applyToFetchRequest(fetchRequest)
|
||||
}
|
||||
|
||||
|
||||
// MARK: CoreStoreBridge
|
||||
// MARK: CoreStoreObjectiveCType
|
||||
|
||||
internal let swift: OrderBy
|
||||
public let bridgeToSwift: OrderBy
|
||||
|
||||
internal init(_ swiftObject: OrderBy) {
|
||||
public init(_ swiftValue: OrderBy) {
|
||||
|
||||
self.swift = swiftObject
|
||||
self.bridgeToSwift = swiftValue
|
||||
super.init()
|
||||
}
|
||||
}
|
||||
@@ -123,9 +123,9 @@ public final class CSOrderBy: NSObject, CSFetchClause, CSQueryClause, CSDeleteCl
|
||||
|
||||
// MARK: - OrderBy
|
||||
|
||||
extension OrderBy: CoreStoreBridgeable {
|
||||
extension OrderBy: CoreStoreSwiftType {
|
||||
|
||||
// MARK: CoreStoreBridgeable
|
||||
// MARK: CoreStoreSwiftType
|
||||
|
||||
internal typealias ObjCType = CSOrderBy
|
||||
public typealias ObjectiveCType = CSOrderBy
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ import CoreData
|
||||
The `CSSQLiteStore` serves as the Objective-C bridging type for `SQLiteStore`.
|
||||
*/
|
||||
@objc
|
||||
public final class CSSQLiteStore: NSObject, CSLocalStorage, CoreStoreBridge {
|
||||
public final class CSSQLiteStore: NSObject, CSLocalStorage, CoreStoreObjectiveCType {
|
||||
|
||||
/**
|
||||
Initializes an SQLite store interface from the given SQLite file URL. When this instance is passed to the `CSDataStack`'s `-addStorage*:` methods, a new SQLite file will be created if it does not exist.
|
||||
@@ -97,7 +97,7 @@ public final class CSSQLiteStore: NSObject, CSLocalStorage, CoreStoreBridge {
|
||||
@objc
|
||||
public var fileURL: NSURL {
|
||||
|
||||
return self.swift.fileURL
|
||||
return self.bridgeToSwift.fileURL
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -106,7 +106,7 @@ public final class CSSQLiteStore: NSObject, CSLocalStorage, CoreStoreBridge {
|
||||
@objc
|
||||
public var mappingModelBundles: [NSBundle] {
|
||||
|
||||
return self.swift.mappingModelBundles
|
||||
return self.bridgeToSwift.mappingModelBundles
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -115,7 +115,7 @@ public final class CSSQLiteStore: NSObject, CSLocalStorage, CoreStoreBridge {
|
||||
@objc
|
||||
public var localStorageOptions: Int {
|
||||
|
||||
return self.swift.localStorageOptions.rawValue
|
||||
return self.bridgeToSwift.localStorageOptions.rawValue
|
||||
}
|
||||
|
||||
|
||||
@@ -132,7 +132,7 @@ public final class CSSQLiteStore: NSObject, CSLocalStorage, CoreStoreBridge {
|
||||
*/
|
||||
public var configuration: String? {
|
||||
|
||||
return self.swift.configuration
|
||||
return self.bridgeToSwift.configuration
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -144,7 +144,7 @@ public final class CSSQLiteStore: NSObject, CSLocalStorage, CoreStoreBridge {
|
||||
@objc
|
||||
public var storeOptions: [String: AnyObject]? {
|
||||
|
||||
return self.swift.storeOptions
|
||||
return self.bridgeToSwift.storeOptions
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -155,7 +155,7 @@ public final class CSSQLiteStore: NSObject, CSLocalStorage, CoreStoreBridge {
|
||||
|
||||
try bridge {
|
||||
|
||||
try self.swift.eraseStorageAndWait(soureModel: soureModel)
|
||||
try self.bridgeToSwift.eraseStorageAndWait(soureModel: soureModel)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -164,7 +164,7 @@ public final class CSSQLiteStore: NSObject, CSLocalStorage, CoreStoreBridge {
|
||||
|
||||
public override var hash: Int {
|
||||
|
||||
return ObjectIdentifier(self.swift).hashValue
|
||||
return ObjectIdentifier(self.bridgeToSwift).hashValue
|
||||
}
|
||||
|
||||
public override func isEqual(object: AnyObject?) -> Bool {
|
||||
@@ -173,17 +173,17 @@ public final class CSSQLiteStore: NSObject, CSLocalStorage, CoreStoreBridge {
|
||||
|
||||
return false
|
||||
}
|
||||
return self.swift === object.swift
|
||||
return self.bridgeToSwift === object.bridgeToSwift
|
||||
}
|
||||
|
||||
|
||||
// MARK: CoreStoreBridge
|
||||
// MARK: CoreStoreObjectiveCType
|
||||
|
||||
internal let swift: SQLiteStore
|
||||
public let bridgeToSwift: SQLiteStore
|
||||
|
||||
public required init(_ swiftObject: SQLiteStore) {
|
||||
public required init(_ swiftValue: SQLiteStore) {
|
||||
|
||||
self.swift = swiftObject
|
||||
self.bridgeToSwift = swiftValue
|
||||
super.init()
|
||||
}
|
||||
}
|
||||
@@ -191,9 +191,9 @@ public final class CSSQLiteStore: NSObject, CSLocalStorage, CoreStoreBridge {
|
||||
|
||||
// MARK: - SQLiteStore
|
||||
|
||||
extension SQLiteStore: CoreStoreBridgeable {
|
||||
extension SQLiteStore: CoreStoreSwiftType {
|
||||
|
||||
// MARK: CoreStoreBridgeable
|
||||
// MARK: CoreStoreSwiftType
|
||||
|
||||
internal typealias ObjCType = CSSQLiteStore
|
||||
public typealias ObjectiveCType = CSSQLiteStore
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ import CoreData
|
||||
The `CSSaveResult` serves as the Objective-C bridging type for `SaveResult`.
|
||||
*/
|
||||
@objc
|
||||
public final class CSSaveResult: NSObject, CoreStoreBridge {
|
||||
public final class CSSaveResult: NSObject, CoreStoreObjectiveCType {
|
||||
|
||||
/**
|
||||
`YES` if the `commit` operation for the transaction succeeded, either because the save succeeded or because there were no changes to save. Returns `NO` to indicate failure.
|
||||
@@ -41,7 +41,7 @@ public final class CSSaveResult: NSObject, CoreStoreBridge {
|
||||
@objc
|
||||
public var isSuccess: Bool {
|
||||
|
||||
return self.swift.boolValue
|
||||
return self.bridgeToSwift.boolValue
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -50,7 +50,7 @@ public final class CSSaveResult: NSObject, CoreStoreBridge {
|
||||
@objc
|
||||
public var isFailure: Bool {
|
||||
|
||||
return !self.swift.boolValue
|
||||
return !self.bridgeToSwift.boolValue
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -59,7 +59,7 @@ public final class CSSaveResult: NSObject, CoreStoreBridge {
|
||||
@objc
|
||||
public var hasChanges: Bool {
|
||||
|
||||
guard case .Success(let hasChanges) = self.swift else {
|
||||
guard case .Success(let hasChanges) = self.bridgeToSwift else {
|
||||
|
||||
return false
|
||||
}
|
||||
@@ -72,11 +72,11 @@ public final class CSSaveResult: NSObject, CoreStoreBridge {
|
||||
@objc
|
||||
public var error: NSError? {
|
||||
|
||||
guard case .Failure(let error) = self.swift else {
|
||||
guard case .Failure(let error) = self.bridgeToSwift else {
|
||||
|
||||
return nil
|
||||
}
|
||||
return error.objc
|
||||
return error.bridgeToObjectiveC
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -90,13 +90,13 @@ public final class CSSaveResult: NSObject, CoreStoreBridge {
|
||||
@objc
|
||||
public func handleSuccess(@noescape success: (hasChanges: Bool) -> Void, @noescape failure: (error: NSError) -> Void) {
|
||||
|
||||
switch self.swift {
|
||||
switch self.bridgeToSwift {
|
||||
|
||||
case .Success(let hasChanges):
|
||||
success(hasChanges: hasChanges)
|
||||
|
||||
case .Failure(let error):
|
||||
failure(error: error.objc)
|
||||
failure(error: error.bridgeToObjectiveC)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ public final class CSSaveResult: NSObject, CoreStoreBridge {
|
||||
@objc
|
||||
public func handleSuccess(@noescape success: (hasChanges: Bool) -> Void) {
|
||||
|
||||
guard case .Success(let hasChanges) = self.swift else {
|
||||
guard case .Success(let hasChanges) = self.bridgeToSwift else {
|
||||
|
||||
return
|
||||
}
|
||||
@@ -127,11 +127,11 @@ public final class CSSaveResult: NSObject, CoreStoreBridge {
|
||||
@objc
|
||||
public func handleFailure(@noescape failure: (error: NSError) -> Void) {
|
||||
|
||||
guard case .Failure(let error) = self.swift else {
|
||||
guard case .Failure(let error) = self.bridgeToSwift else {
|
||||
|
||||
return
|
||||
}
|
||||
failure(error: error.objc)
|
||||
failure(error: error.bridgeToObjectiveC)
|
||||
}
|
||||
|
||||
|
||||
@@ -139,7 +139,7 @@ public final class CSSaveResult: NSObject, CoreStoreBridge {
|
||||
|
||||
public override var hash: Int {
|
||||
|
||||
return self.swift.hashValue
|
||||
return self.bridgeToSwift.hashValue
|
||||
}
|
||||
|
||||
public override func isEqual(object: AnyObject?) -> Bool {
|
||||
@@ -148,17 +148,17 @@ public final class CSSaveResult: NSObject, CoreStoreBridge {
|
||||
|
||||
return false
|
||||
}
|
||||
return self.swift == object.swift
|
||||
return self.bridgeToSwift == object.bridgeToSwift
|
||||
}
|
||||
|
||||
|
||||
// MARK: CoreStoreBridge
|
||||
// MARK: CoreStoreObjectiveCType
|
||||
|
||||
internal let swift: SaveResult
|
||||
public let bridgeToSwift: SaveResult
|
||||
|
||||
public required init(_ swiftObject: SaveResult) {
|
||||
public required init(_ swiftValue: SaveResult) {
|
||||
|
||||
self.swift = swiftObject
|
||||
self.bridgeToSwift = swiftValue
|
||||
super.init()
|
||||
}
|
||||
}
|
||||
@@ -166,9 +166,9 @@ public final class CSSaveResult: NSObject, CoreStoreBridge {
|
||||
|
||||
// MARK: - SaveResult
|
||||
|
||||
extension SaveResult: CoreStoreBridgeable {
|
||||
extension SaveResult: CoreStoreSwiftType {
|
||||
|
||||
// MARK: CoreStoreBridgeable
|
||||
// MARK: CoreStoreSwiftType
|
||||
|
||||
internal typealias ObjCType = CSSaveResult
|
||||
public typealias ObjectiveCType = CSSaveResult
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ import CoreData
|
||||
*/
|
||||
@available(OSX, unavailable)
|
||||
@objc
|
||||
public final class CSSectionBy: NSObject, CoreStoreBridge {
|
||||
public final class CSSectionBy: NSObject, CoreStoreObjectiveCType {
|
||||
|
||||
/**
|
||||
Initializes a `CSSectionBy` clause with the key path to use to group `CSListMonitor` objects into sections
|
||||
@@ -62,13 +62,13 @@ public final class CSSectionBy: NSObject, CoreStoreBridge {
|
||||
}
|
||||
|
||||
|
||||
// MARK: CoreStoreBridge
|
||||
// MARK: CoreStoreObjectiveCType
|
||||
|
||||
internal let swift: SectionBy
|
||||
public let bridgeToSwift: SectionBy
|
||||
|
||||
internal init(_ swiftObject: SectionBy) {
|
||||
public init(_ swiftValue: SectionBy) {
|
||||
|
||||
self.swift = swiftObject
|
||||
self.bridgeToSwift = swiftValue
|
||||
super.init()
|
||||
}
|
||||
}
|
||||
@@ -76,9 +76,9 @@ public final class CSSectionBy: NSObject, CoreStoreBridge {
|
||||
|
||||
// MARK: - SectionBy
|
||||
|
||||
extension SectionBy: CoreStoreBridgeable {
|
||||
extension SectionBy: CoreStoreSwiftType {
|
||||
|
||||
// MARK: CoreStoreBridgeable
|
||||
// MARK: CoreStoreSwiftType
|
||||
|
||||
internal typealias ObjCType = CSSectionBy
|
||||
public typealias ObjectiveCType = CSSectionBy
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ public final class CSSynchronousDataTransaction: CSBaseDataTransaction {
|
||||
|
||||
return bridge {
|
||||
|
||||
self.swift.commitAndWait()
|
||||
self.bridgeToSwift.commitAndWait()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,9 +60,9 @@ public final class CSSynchronousDataTransaction: CSBaseDataTransaction {
|
||||
|
||||
return bridge {
|
||||
|
||||
self.swift.beginSynchronous { (transaction) in
|
||||
self.bridgeToSwift.beginSynchronous { (transaction) in
|
||||
|
||||
closure(transaction: transaction.objc)
|
||||
closure(transaction: transaction.bridgeToObjectiveC)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -79,7 +79,7 @@ public final class CSSynchronousDataTransaction: CSBaseDataTransaction {
|
||||
@objc
|
||||
public override func createInto(into: CSInto) -> NSManagedObject {
|
||||
|
||||
return self.swift.create(into.swift)
|
||||
return self.bridgeToSwift.create(into.bridgeToSwift)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -92,7 +92,7 @@ public final class CSSynchronousDataTransaction: CSBaseDataTransaction {
|
||||
@warn_unused_result
|
||||
public override func editObject(object: NSManagedObject?) -> NSManagedObject? {
|
||||
|
||||
return self.swift.edit(object)
|
||||
return self.bridgeToSwift.edit(object)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -106,7 +106,7 @@ public final class CSSynchronousDataTransaction: CSBaseDataTransaction {
|
||||
@warn_unused_result
|
||||
public override func editInto(into: CSInto, objectID: NSManagedObjectID) -> NSManagedObject? {
|
||||
|
||||
return self.swift.edit(into.swift, objectID)
|
||||
return self.bridgeToSwift.edit(into.bridgeToSwift, objectID)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -117,7 +117,7 @@ public final class CSSynchronousDataTransaction: CSBaseDataTransaction {
|
||||
@objc
|
||||
public override func deleteObject(object: NSManagedObject?) {
|
||||
|
||||
return self.swift.delete(object)
|
||||
return self.bridgeToSwift.delete(object)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -127,27 +127,27 @@ public final class CSSynchronousDataTransaction: CSBaseDataTransaction {
|
||||
*/
|
||||
public override func deleteObjects(objects: [NSManagedObject]) {
|
||||
|
||||
self.swift.delete(objects)
|
||||
self.bridgeToSwift.delete(objects)
|
||||
}
|
||||
|
||||
|
||||
// MARK: CoreStoreBridge
|
||||
// MARK: CoreStoreObjectiveCType
|
||||
|
||||
internal typealias SwiftType = SynchronousDataTransaction
|
||||
|
||||
internal override var swift: SynchronousDataTransaction {
|
||||
public override var bridgeToSwift: SynchronousDataTransaction {
|
||||
|
||||
return super.swift as! SynchronousDataTransaction
|
||||
return super.bridgeToSwift as! SynchronousDataTransaction
|
||||
}
|
||||
|
||||
public required init(_ swiftObject: SynchronousDataTransaction) {
|
||||
public required init(_ swiftValue: SynchronousDataTransaction) {
|
||||
|
||||
super.init(swiftObject)
|
||||
super.init(swiftValue)
|
||||
}
|
||||
|
||||
required public init(_ swiftObject: BaseDataTransaction) {
|
||||
public required init(_ swiftValue: BaseDataTransaction) {
|
||||
|
||||
fatalError("init has not been implemented")
|
||||
fatalError("init(_:) requires a BaseDataTransaction instance")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,7 +156,7 @@ public final class CSSynchronousDataTransaction: CSBaseDataTransaction {
|
||||
|
||||
extension SynchronousDataTransaction {
|
||||
|
||||
// MARK: CoreStoreBridgeable
|
||||
// MARK: CoreStoreSwiftType
|
||||
|
||||
internal typealias ObjCType = CSSynchronousDataTransaction
|
||||
internal typealias ObjectiveCType = CSSynchronousDataTransaction
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ import CoreData
|
||||
The `CSTweak` serves as the Objective-C bridging type for `Tweak`.
|
||||
*/
|
||||
@objc
|
||||
public final class CSTweak: NSObject, CSFetchClause, CSQueryClause, CSDeleteClause, CoreStoreBridge {
|
||||
public final class CSTweak: NSObject, CSFetchClause, CSQueryClause, CSDeleteClause, CoreStoreObjectiveCType {
|
||||
|
||||
/**
|
||||
Initializes a `CSTweak` clause with a closure where the `NSFetchRequest` may be configured.
|
||||
@@ -53,17 +53,17 @@ public final class CSTweak: NSObject, CSFetchClause, CSQueryClause, CSDeleteClau
|
||||
@objc
|
||||
public func applyToFetchRequest(fetchRequest: NSFetchRequest) {
|
||||
|
||||
self.swift.applyToFetchRequest(fetchRequest)
|
||||
self.bridgeToSwift.applyToFetchRequest(fetchRequest)
|
||||
}
|
||||
|
||||
|
||||
// MARK: CoreStoreBridge
|
||||
// MARK: CoreStoreObjectiveCType
|
||||
|
||||
internal let swift: Tweak
|
||||
public let bridgeToSwift: Tweak
|
||||
|
||||
internal init(_ swiftObject: Tweak) {
|
||||
public init(_ swiftValue: Tweak) {
|
||||
|
||||
self.swift = swiftObject
|
||||
self.bridgeToSwift = swiftValue
|
||||
super.init()
|
||||
}
|
||||
}
|
||||
@@ -71,9 +71,9 @@ public final class CSTweak: NSObject, CSFetchClause, CSQueryClause, CSDeleteClau
|
||||
|
||||
// MARK: - Tweak
|
||||
|
||||
extension Tweak: CoreStoreBridgeable {
|
||||
extension Tweak: CoreStoreSwiftType {
|
||||
|
||||
// MARK: CoreStoreBridgeable
|
||||
// MARK: CoreStoreSwiftType
|
||||
|
||||
internal typealias ObjCType = CSTweak
|
||||
public typealias ObjectiveCType = CSTweak
|
||||
}
|
||||
|
||||
@@ -43,9 +43,9 @@ public final class CSUnsafeDataTransaction: CSBaseDataTransaction {
|
||||
@objc
|
||||
public func commit(completion: ((result: CSSaveResult) -> Void)?) {
|
||||
|
||||
self.swift.commit { (result) in
|
||||
self.bridgeToSwift.commit { (result) in
|
||||
|
||||
completion?(result: result.objc)
|
||||
completion?(result: result.bridgeToObjectiveC)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ public final class CSUnsafeDataTransaction: CSBaseDataTransaction {
|
||||
|
||||
return bridge {
|
||||
|
||||
self.swift.commitAndWait()
|
||||
self.bridgeToSwift.commitAndWait()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ public final class CSUnsafeDataTransaction: CSBaseDataTransaction {
|
||||
@objc
|
||||
public func rollback() {
|
||||
|
||||
self.swift.rollback()
|
||||
self.bridgeToSwift.rollback()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -78,7 +78,7 @@ public final class CSUnsafeDataTransaction: CSBaseDataTransaction {
|
||||
@objc
|
||||
public func undo() {
|
||||
|
||||
self.swift.undo()
|
||||
self.bridgeToSwift.undo()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -87,7 +87,7 @@ public final class CSUnsafeDataTransaction: CSBaseDataTransaction {
|
||||
@objc
|
||||
public func redo() {
|
||||
|
||||
self.swift.redo()
|
||||
self.bridgeToSwift.redo()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -102,7 +102,7 @@ public final class CSUnsafeDataTransaction: CSBaseDataTransaction {
|
||||
|
||||
return bridge {
|
||||
|
||||
self.swift.beginUnsafe()
|
||||
self.bridgeToSwift.beginUnsafe()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ public final class CSUnsafeDataTransaction: CSBaseDataTransaction {
|
||||
|
||||
return bridge {
|
||||
|
||||
self.swift.beginUnsafe(supportsUndo: supportsUndo)
|
||||
self.bridgeToSwift.beginUnsafe(supportsUndo: supportsUndo)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,27 +132,27 @@ public final class CSUnsafeDataTransaction: CSBaseDataTransaction {
|
||||
@objc
|
||||
public var internalContext: NSManagedObjectContext {
|
||||
|
||||
return self.swift.context
|
||||
return self.bridgeToSwift.context
|
||||
}
|
||||
|
||||
|
||||
// MARK: CoreStoreBridge
|
||||
// MARK: CoreStoreObjectiveCType
|
||||
|
||||
internal typealias SwiftType = UnsafeDataTransaction
|
||||
|
||||
internal override var swift: UnsafeDataTransaction {
|
||||
public override var bridgeToSwift: UnsafeDataTransaction {
|
||||
|
||||
return super.swift as! UnsafeDataTransaction
|
||||
return super.bridgeToSwift as! UnsafeDataTransaction
|
||||
}
|
||||
|
||||
public required init(_ swiftObject: UnsafeDataTransaction) {
|
||||
public required init(_ swiftValue: UnsafeDataTransaction) {
|
||||
|
||||
super.init(swiftObject)
|
||||
super.init(swiftValue)
|
||||
}
|
||||
|
||||
required public init(_ swiftObject: BaseDataTransaction) {
|
||||
public required init(_ swiftValue: BaseDataTransaction) {
|
||||
|
||||
fatalError("init has not been implemented")
|
||||
fatalError("init(_:) requires an UnsafeDataTransaction instance")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,7 +161,7 @@ public final class CSUnsafeDataTransaction: CSBaseDataTransaction {
|
||||
|
||||
extension UnsafeDataTransaction {
|
||||
|
||||
// MARK: CoreStoreBridgeable
|
||||
// MARK: CoreStoreSwiftType
|
||||
|
||||
internal typealias ObjCType = CSUnsafeDataTransaction
|
||||
internal typealias ObjectiveCType = CSUnsafeDataTransaction
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ import CoreData
|
||||
The `CSWhere` serves as the Objective-C bridging type for `Where`.
|
||||
*/
|
||||
@objc
|
||||
public final class CSWhere: NSObject, CSFetchClause, CSQueryClause, CSDeleteClause, CoreStoreBridge {
|
||||
public final class CSWhere: NSObject, CSFetchClause, CSQueryClause, CSDeleteClause, CoreStoreObjectiveCType {
|
||||
|
||||
/**
|
||||
Initializes a `CSWhere` clause with an `NSPredicate`
|
||||
@@ -103,7 +103,7 @@ public final class CSWhere: NSObject, CSFetchClause, CSQueryClause, CSDeleteClau
|
||||
|
||||
public override var hash: Int {
|
||||
|
||||
return self.swift.hashValue
|
||||
return self.bridgeToSwift.hashValue
|
||||
}
|
||||
|
||||
public override func isEqual(object: AnyObject?) -> Bool {
|
||||
@@ -112,7 +112,7 @@ public final class CSWhere: NSObject, CSFetchClause, CSQueryClause, CSDeleteClau
|
||||
|
||||
return false
|
||||
}
|
||||
return self.swift == object.swift
|
||||
return self.bridgeToSwift == object.bridgeToSwift
|
||||
}
|
||||
|
||||
|
||||
@@ -121,17 +121,17 @@ public final class CSWhere: NSObject, CSFetchClause, CSQueryClause, CSDeleteClau
|
||||
@objc
|
||||
public func applyToFetchRequest(fetchRequest: NSFetchRequest) {
|
||||
|
||||
self.swift.applyToFetchRequest(fetchRequest)
|
||||
self.bridgeToSwift.applyToFetchRequest(fetchRequest)
|
||||
}
|
||||
|
||||
|
||||
// MARK: CoreStoreBridge
|
||||
// MARK: CoreStoreObjectiveCType
|
||||
|
||||
internal let swift: Where
|
||||
public let bridgeToSwift: Where
|
||||
|
||||
internal init(_ swiftObject: Where) {
|
||||
public init(_ swiftValue: Where) {
|
||||
|
||||
self.swift = swiftObject
|
||||
self.bridgeToSwift = swiftValue
|
||||
super.init()
|
||||
}
|
||||
}
|
||||
@@ -139,9 +139,9 @@ public final class CSWhere: NSObject, CSFetchClause, CSQueryClause, CSDeleteClau
|
||||
|
||||
// MARK: - Where
|
||||
|
||||
extension Where: CoreStoreBridgeable {
|
||||
extension Where: CoreStoreSwiftType {
|
||||
|
||||
// MARK: CoreStoreBridgeable
|
||||
// MARK: CoreStoreSwiftType
|
||||
|
||||
internal typealias ObjCType = CSWhere
|
||||
public typealias ObjectiveCType = CSWhere
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// CoreStoreBridge.swift
|
||||
// CoreStoreObjectiveCType.swift
|
||||
// CoreStore
|
||||
//
|
||||
// Copyright © 2016 John Rommel Estropia
|
||||
@@ -26,57 +26,57 @@
|
||||
import Foundation
|
||||
|
||||
|
||||
// MARK: - CoreStoreBridge
|
||||
// MARK: - CoreStoreObjectiveCType
|
||||
|
||||
internal protocol CoreStoreBridge: class, AnyObject {
|
||||
public protocol CoreStoreObjectiveCType: class, AnyObject {
|
||||
|
||||
associatedtype SwiftType
|
||||
|
||||
var swift: SwiftType { get }
|
||||
var bridgeToSwift: SwiftType { get }
|
||||
|
||||
init(_ swiftObject: SwiftType)
|
||||
init(_ swiftValue: SwiftType)
|
||||
}
|
||||
|
||||
|
||||
// MARK: - CoreStoreBridgeable
|
||||
// MARK: - CoreStoreSwiftType
|
||||
|
||||
internal protocol CoreStoreBridgeable {
|
||||
public protocol CoreStoreSwiftType {
|
||||
|
||||
associatedtype ObjCType: CoreStoreBridge
|
||||
associatedtype ObjectiveCType: CoreStoreObjectiveCType
|
||||
|
||||
var objc: ObjCType { get }
|
||||
var bridgeToObjectiveC: ObjectiveCType { get }
|
||||
}
|
||||
|
||||
internal extension CoreStoreBridgeable where Self == ObjCType.SwiftType {
|
||||
public extension CoreStoreSwiftType where Self == ObjectiveCType.SwiftType {
|
||||
|
||||
var objc: ObjCType {
|
||||
public var bridgeToObjectiveC: ObjectiveCType {
|
||||
|
||||
return ObjCType(self)
|
||||
return ObjectiveCType(self)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - Internal
|
||||
|
||||
internal func bridge<T: CoreStoreBridgeable where T == T.ObjCType.SwiftType>(@noescape closure: () -> T) -> T.ObjCType {
|
||||
internal func bridge<T: CoreStoreSwiftType where T == T.ObjectiveCType.SwiftType>(@noescape closure: () -> T) -> T.ObjectiveCType {
|
||||
|
||||
return closure().objc
|
||||
return closure().bridgeToObjectiveC
|
||||
}
|
||||
|
||||
internal func bridge<T: CoreStoreBridgeable where T == T.ObjCType.SwiftType>(@noescape closure: () -> T?) -> T.ObjCType? {
|
||||
internal func bridge<T: CoreStoreSwiftType where T == T.ObjectiveCType.SwiftType>(@noescape closure: () -> T?) -> T.ObjectiveCType? {
|
||||
|
||||
return closure()?.objc
|
||||
return closure()?.bridgeToObjectiveC
|
||||
}
|
||||
|
||||
internal func bridge<T: CoreStoreBridgeable where T == T.ObjCType.SwiftType>(@noescape closure: () throws -> T) throws -> T.ObjCType {
|
||||
internal func bridge<T: CoreStoreSwiftType where T == T.ObjectiveCType.SwiftType>(@noescape closure: () throws -> T) throws -> T.ObjectiveCType {
|
||||
|
||||
do {
|
||||
|
||||
return try closure().objc
|
||||
return try closure().bridgeToObjectiveC
|
||||
}
|
||||
catch {
|
||||
|
||||
throw error.objc
|
||||
throw error.bridgeToObjectiveC
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ internal func bridge(@noescape closure: () throws -> Void) throws {
|
||||
}
|
||||
catch {
|
||||
|
||||
throw error.objc
|
||||
throw error.bridgeToObjectiveC
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ internal func bridge<T>(error: NSErrorPointer, @noescape _ closure: () throws ->
|
||||
}
|
||||
catch let swiftError {
|
||||
|
||||
error.memory = swiftError.objc
|
||||
error.memory = swiftError.bridgeToObjectiveC
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ internal extension NSManagedObjectContext {
|
||||
internal func fetchOne(from: CSFrom, _ fetchClauses: [CSFetchClause]) -> NSManagedObject? {
|
||||
|
||||
let fetchRequest = NSFetchRequest()
|
||||
from.swift.applyToFetchRequest(fetchRequest, context: self)
|
||||
from.bridgeToSwift.applyToFetchRequest(fetchRequest, context: self)
|
||||
|
||||
fetchRequest.fetchLimit = 1
|
||||
fetchRequest.resultType = .ManagedObjectResultType
|
||||
@@ -50,7 +50,7 @@ internal extension NSManagedObjectContext {
|
||||
internal func fetchAll(from: CSFrom, _ fetchClauses: [CSFetchClause]) -> [NSManagedObject]? {
|
||||
|
||||
let fetchRequest = NSFetchRequest()
|
||||
from.swift.applyToFetchRequest(fetchRequest, context: self)
|
||||
from.bridgeToSwift.applyToFetchRequest(fetchRequest, context: self)
|
||||
|
||||
fetchRequest.fetchLimit = 0
|
||||
fetchRequest.resultType = .ManagedObjectResultType
|
||||
@@ -63,7 +63,7 @@ internal extension NSManagedObjectContext {
|
||||
internal func fetchCount(from: CSFrom, _ fetchClauses: [CSFetchClause]) -> Int? {
|
||||
|
||||
let fetchRequest = NSFetchRequest()
|
||||
from.swift.applyToFetchRequest(fetchRequest, context: self)
|
||||
from.bridgeToSwift.applyToFetchRequest(fetchRequest, context: self)
|
||||
fetchClauses.forEach { $0.applyToFetchRequest(fetchRequest) }
|
||||
|
||||
return self.fetchCount(fetchRequest)
|
||||
@@ -73,7 +73,7 @@ internal extension NSManagedObjectContext {
|
||||
internal func fetchObjectID(from: CSFrom, _ fetchClauses: [CSFetchClause]) -> NSManagedObjectID? {
|
||||
|
||||
let fetchRequest = NSFetchRequest()
|
||||
from.swift.applyToFetchRequest(fetchRequest, context: self)
|
||||
from.bridgeToSwift.applyToFetchRequest(fetchRequest, context: self)
|
||||
|
||||
fetchRequest.fetchLimit = 1
|
||||
fetchRequest.resultType = .ManagedObjectIDResultType
|
||||
@@ -86,7 +86,7 @@ internal extension NSManagedObjectContext {
|
||||
internal func fetchObjectIDs(from: CSFrom, _ fetchClauses: [CSFetchClause]) -> [NSManagedObjectID]? {
|
||||
|
||||
let fetchRequest = NSFetchRequest()
|
||||
from.swift.applyToFetchRequest(fetchRequest, context: self)
|
||||
from.bridgeToSwift.applyToFetchRequest(fetchRequest, context: self)
|
||||
|
||||
fetchRequest.fetchLimit = 0
|
||||
fetchRequest.resultType = .ManagedObjectIDResultType
|
||||
@@ -99,7 +99,7 @@ internal extension NSManagedObjectContext {
|
||||
internal func deleteAll(from: CSFrom, _ deleteClauses: [CSDeleteClause]) -> Int? {
|
||||
|
||||
let fetchRequest = NSFetchRequest()
|
||||
from.swift.applyToFetchRequest(fetchRequest, context: self)
|
||||
from.bridgeToSwift.applyToFetchRequest(fetchRequest, context: self)
|
||||
|
||||
fetchRequest.fetchLimit = 0
|
||||
fetchRequest.resultType = .ManagedObjectResultType
|
||||
|
||||
Reference in New Issue
Block a user