mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-01-15 13:43:43 +01:00
fix bridging producing base abstract class instead of subclass concrete class
This commit is contained in:
@@ -197,4 +197,41 @@
|
||||
XCTAssertNil(sqliteError);
|
||||
}
|
||||
|
||||
- (void)test_ThatTransactions_BridgeCorrectly {
|
||||
|
||||
[CSCoreStore
|
||||
setDefaultStack:[[CSDataStack alloc]
|
||||
initWithModelName:@"Model"
|
||||
bundle:[NSBundle bundleForClass:[self class]]
|
||||
versionChain:nil]];
|
||||
[CSCoreStore
|
||||
addInMemoryStorageAndWait:[CSInMemoryStore new]
|
||||
error:nil];
|
||||
|
||||
{
|
||||
CSUnsafeDataTransaction *transaction = [CSCoreStore beginUnsafe];
|
||||
XCTAssertNotNil(transaction);
|
||||
XCTAssert([transaction isKindOfClass:[CSUnsafeDataTransaction class]]);
|
||||
}
|
||||
{
|
||||
XCTestExpectation *expectation = [self expectationWithDescription:@"sync"];
|
||||
[CSCoreStore beginSynchronous:^(CSSynchronousDataTransaction * _Nonnull transaction) {
|
||||
|
||||
XCTAssertNotNil(transaction);
|
||||
XCTAssert([transaction isKindOfClass:[CSSynchronousDataTransaction class]]);
|
||||
[expectation fulfill];
|
||||
}];
|
||||
}
|
||||
{
|
||||
XCTestExpectation *expectation = [self expectationWithDescription:@"async"];
|
||||
[CSCoreStore beginAsynchronous:^(CSAsynchronousDataTransaction * _Nonnull transaction) {
|
||||
|
||||
XCTAssertNotNil(transaction);
|
||||
XCTAssert([transaction isKindOfClass:[CSAsynchronousDataTransaction class]]);
|
||||
[expectation fulfill];
|
||||
}];
|
||||
}
|
||||
[self waitForExpectationsWithTimeout:10 handler:nil];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -144,7 +144,7 @@ public final class CSAsynchronousDataTransaction: CSBaseDataTransaction {
|
||||
|
||||
// MARK: CoreStoreObjectiveCType
|
||||
|
||||
internal typealias SwiftType = AsynchronousDataTransaction
|
||||
public typealias SwiftType = AsynchronousDataTransaction
|
||||
|
||||
public override var bridgeToSwift: AsynchronousDataTransaction {
|
||||
|
||||
@@ -153,21 +153,21 @@ public final class CSAsynchronousDataTransaction: CSBaseDataTransaction {
|
||||
|
||||
public required init(_ swiftValue: AsynchronousDataTransaction) {
|
||||
|
||||
super.init(swiftValue)
|
||||
super.init(swiftValue as BaseDataTransaction)
|
||||
}
|
||||
|
||||
public required init(_ swiftValue: BaseDataTransaction) {
|
||||
|
||||
fatalError("init(_:) requires an AsynchronousDataTransaction instance")
|
||||
super.init(swiftValue as! AsynchronousDataTransaction)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - AsynchronousDataTransaction
|
||||
|
||||
extension AsynchronousDataTransaction {
|
||||
extension AsynchronousDataTransaction: CoreStoreSwiftType {
|
||||
|
||||
// MARK: CoreStoreSwiftType
|
||||
|
||||
internal typealias ObjectiveCType = CSAsynchronousDataTransaction
|
||||
public typealias ObjectiveCType = CSAsynchronousDataTransaction
|
||||
}
|
||||
|
||||
@@ -292,8 +292,6 @@ public class CSBaseDataTransaction: NSObject, CoreStoreObjectiveCType {
|
||||
|
||||
// MARK: CoreStoreObjectiveCType
|
||||
|
||||
public typealias SwiftType = BaseDataTransaction
|
||||
|
||||
public required init(_ swiftValue: BaseDataTransaction) {
|
||||
|
||||
self.swiftTransaction = swiftValue
|
||||
@@ -312,11 +310,11 @@ public class CSBaseDataTransaction: NSObject, CoreStoreObjectiveCType {
|
||||
}
|
||||
|
||||
|
||||
// MARK: - BaseDataTransaction
|
||||
|
||||
extension BaseDataTransaction: CoreStoreSwiftType {
|
||||
|
||||
// MARK: CoreStoreSwiftType
|
||||
|
||||
public typealias ObjectiveCType = CSBaseDataTransaction
|
||||
}
|
||||
//// MARK: - BaseDataTransaction
|
||||
//
|
||||
//extension BaseDataTransaction: CoreStoreSwiftType {
|
||||
//
|
||||
// // MARK: CoreStoreSwiftType
|
||||
//
|
||||
// public typealias ObjectiveCType = CSBaseDataTransaction
|
||||
//}
|
||||
|
||||
@@ -143,7 +143,7 @@ public final class CSSynchronousDataTransaction: CSBaseDataTransaction {
|
||||
|
||||
// MARK: CoreStoreObjectiveCType
|
||||
|
||||
internal typealias SwiftType = SynchronousDataTransaction
|
||||
public typealias SwiftType = SynchronousDataTransaction
|
||||
|
||||
public override var bridgeToSwift: SynchronousDataTransaction {
|
||||
|
||||
@@ -152,21 +152,21 @@ public final class CSSynchronousDataTransaction: CSBaseDataTransaction {
|
||||
|
||||
public required init(_ swiftValue: SynchronousDataTransaction) {
|
||||
|
||||
super.init(swiftValue)
|
||||
super.init(swiftValue as BaseDataTransaction)
|
||||
}
|
||||
|
||||
public required init(_ swiftValue: BaseDataTransaction) {
|
||||
|
||||
fatalError("init(_:) requires a BaseDataTransaction instance")
|
||||
super.init(swiftValue as! SynchronousDataTransaction)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - SynchronousDataTransaction
|
||||
|
||||
extension SynchronousDataTransaction {
|
||||
extension SynchronousDataTransaction: CoreStoreSwiftType {
|
||||
|
||||
// MARK: CoreStoreSwiftType
|
||||
|
||||
internal typealias ObjectiveCType = CSSynchronousDataTransaction
|
||||
public typealias ObjectiveCType = CSSynchronousDataTransaction
|
||||
}
|
||||
|
||||
@@ -174,7 +174,7 @@ public final class CSUnsafeDataTransaction: CSBaseDataTransaction {
|
||||
|
||||
// MARK: CoreStoreObjectiveCType
|
||||
|
||||
internal typealias SwiftType = UnsafeDataTransaction
|
||||
public typealias SwiftType = UnsafeDataTransaction
|
||||
|
||||
public override var bridgeToSwift: UnsafeDataTransaction {
|
||||
|
||||
@@ -183,21 +183,21 @@ public final class CSUnsafeDataTransaction: CSBaseDataTransaction {
|
||||
|
||||
public required init(_ swiftValue: UnsafeDataTransaction) {
|
||||
|
||||
super.init(swiftValue)
|
||||
super.init(swiftValue as BaseDataTransaction)
|
||||
}
|
||||
|
||||
public required init(_ swiftValue: BaseDataTransaction) {
|
||||
|
||||
fatalError("init(_:) requires an UnsafeDataTransaction instance")
|
||||
super.init(swiftValue as! UnsafeDataTransaction)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - UnsafeDataTransaction
|
||||
|
||||
extension UnsafeDataTransaction {
|
||||
extension UnsafeDataTransaction: CoreStoreSwiftType {
|
||||
|
||||
// MARK: CoreStoreSwiftType
|
||||
|
||||
internal typealias ObjectiveCType = CSUnsafeDataTransaction
|
||||
public typealias ObjectiveCType = CSUnsafeDataTransaction
|
||||
}
|
||||
|
||||
@@ -118,12 +118,18 @@ internal func bridge<T: CoreStoreSwiftType>(error: NSErrorPointer, @noescape _ c
|
||||
do {
|
||||
|
||||
let result = try closure()
|
||||
error.memory = nil
|
||||
if error != nil {
|
||||
|
||||
error.memory = nil
|
||||
}
|
||||
return result.bridgeToObjectiveC
|
||||
}
|
||||
catch let swiftError {
|
||||
|
||||
error.memory = swiftError.bridgeToObjectiveC
|
||||
if error != nil {
|
||||
|
||||
error.memory = swiftError.bridgeToObjectiveC
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
@@ -133,12 +139,18 @@ internal func bridge(error: NSErrorPointer, @noescape _ closure: () throws -> Vo
|
||||
do {
|
||||
|
||||
try closure()
|
||||
error.memory = nil
|
||||
if error != nil {
|
||||
|
||||
error.memory = nil
|
||||
}
|
||||
return true
|
||||
}
|
||||
catch let swiftError {
|
||||
|
||||
error.memory = swiftError.bridgeToObjectiveC
|
||||
if error != nil {
|
||||
|
||||
error.memory = swiftError.bridgeToObjectiveC
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
@@ -148,12 +160,18 @@ internal func bridge<T>(error: NSErrorPointer, @noescape _ closure: () throws ->
|
||||
do {
|
||||
|
||||
let result = try closure()
|
||||
error.memory = nil
|
||||
if error != nil {
|
||||
|
||||
error.memory = nil
|
||||
}
|
||||
return result
|
||||
}
|
||||
catch let swiftError {
|
||||
|
||||
error.memory = swiftError.bridgeToObjectiveC
|
||||
if error != nil {
|
||||
|
||||
error.memory = swiftError.bridgeToObjectiveC
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
@@ -163,12 +181,18 @@ internal func bridge<T: CoreStoreSwiftType>(error: NSErrorPointer, @noescape _ c
|
||||
do {
|
||||
|
||||
let result = try closure()
|
||||
error.memory = nil
|
||||
if error != nil {
|
||||
|
||||
error.memory = nil
|
||||
}
|
||||
return result.map { $0.bridgeToObjectiveC }
|
||||
}
|
||||
catch let swiftError {
|
||||
|
||||
error.memory = swiftError.bridgeToObjectiveC
|
||||
if error != nil {
|
||||
|
||||
error.memory = swiftError.bridgeToObjectiveC
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user