WIP: transactions in ObjC

This commit is contained in:
John Estropia
2016-03-23 11:32:35 +09:00
parent 24008d62b2
commit 2c65ac1834
14 changed files with 893 additions and 75 deletions

View File

@@ -25,6 +25,9 @@
import Foundation
// MARK: - CoreStoreBridge
public protocol CoreStoreBridge: class, AnyObject {
associatedtype SwiftType
@@ -34,6 +37,9 @@ public protocol CoreStoreBridge: class, AnyObject {
init(_ swiftObject: SwiftType)
}
// MARK: - CoreStoreBridgeable
public protocol CoreStoreBridgeable: _ObjectiveCBridgeable {
associatedtype ObjCType: CoreStoreBridge
@@ -72,3 +78,37 @@ public extension CoreStoreBridgeable where Self == ObjCType.SwiftType {
return self._bridgeToObjectiveC()
}
}
// MARK: - Internal
internal func bridge<T: CoreStoreBridgeable where T == T.ObjCType.SwiftType>(@noescape closure: () -> T) -> T.ObjCType {
return closure().objc
}
internal func bridge<T: CoreStoreBridgeable where T == T.ObjCType.SwiftType>(@noescape closure: () throws -> T) throws -> T.ObjCType {
do {
return try closure().objc
}
catch {
throw error.objc
}
}
internal func bridge(@noescape closure: () throws -> Void) throws {
do {
try closure()
}
catch {
throw error.objc
}
}