mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-03-26 11:21:32 +01:00
fix bridging producing base abstract class instead of subclass concrete class
This commit is contained in:
@@ -197,4 +197,41 @@
|
|||||||
XCTAssertNil(sqliteError);
|
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
|
@end
|
||||||
|
|||||||
@@ -144,7 +144,7 @@ public final class CSAsynchronousDataTransaction: CSBaseDataTransaction {
|
|||||||
|
|
||||||
// MARK: CoreStoreObjectiveCType
|
// MARK: CoreStoreObjectiveCType
|
||||||
|
|
||||||
internal typealias SwiftType = AsynchronousDataTransaction
|
public typealias SwiftType = AsynchronousDataTransaction
|
||||||
|
|
||||||
public override var bridgeToSwift: AsynchronousDataTransaction {
|
public override var bridgeToSwift: AsynchronousDataTransaction {
|
||||||
|
|
||||||
@@ -153,21 +153,21 @@ public final class CSAsynchronousDataTransaction: CSBaseDataTransaction {
|
|||||||
|
|
||||||
public required init(_ swiftValue: AsynchronousDataTransaction) {
|
public required init(_ swiftValue: AsynchronousDataTransaction) {
|
||||||
|
|
||||||
super.init(swiftValue)
|
super.init(swiftValue as BaseDataTransaction)
|
||||||
}
|
}
|
||||||
|
|
||||||
public required init(_ swiftValue: BaseDataTransaction) {
|
public required init(_ swiftValue: BaseDataTransaction) {
|
||||||
|
|
||||||
fatalError("init(_:) requires an AsynchronousDataTransaction instance")
|
super.init(swiftValue as! AsynchronousDataTransaction)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// MARK: - AsynchronousDataTransaction
|
// MARK: - AsynchronousDataTransaction
|
||||||
|
|
||||||
extension AsynchronousDataTransaction {
|
extension AsynchronousDataTransaction: CoreStoreSwiftType {
|
||||||
|
|
||||||
// MARK: CoreStoreSwiftType
|
// MARK: CoreStoreSwiftType
|
||||||
|
|
||||||
internal typealias ObjectiveCType = CSAsynchronousDataTransaction
|
public typealias ObjectiveCType = CSAsynchronousDataTransaction
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -292,8 +292,6 @@ public class CSBaseDataTransaction: NSObject, CoreStoreObjectiveCType {
|
|||||||
|
|
||||||
// MARK: CoreStoreObjectiveCType
|
// MARK: CoreStoreObjectiveCType
|
||||||
|
|
||||||
public typealias SwiftType = BaseDataTransaction
|
|
||||||
|
|
||||||
public required init(_ swiftValue: BaseDataTransaction) {
|
public required init(_ swiftValue: BaseDataTransaction) {
|
||||||
|
|
||||||
self.swiftTransaction = swiftValue
|
self.swiftTransaction = swiftValue
|
||||||
@@ -312,11 +310,11 @@ public class CSBaseDataTransaction: NSObject, CoreStoreObjectiveCType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// MARK: - BaseDataTransaction
|
//// MARK: - BaseDataTransaction
|
||||||
|
//
|
||||||
extension BaseDataTransaction: CoreStoreSwiftType {
|
//extension BaseDataTransaction: CoreStoreSwiftType {
|
||||||
|
//
|
||||||
// MARK: CoreStoreSwiftType
|
// // MARK: CoreStoreSwiftType
|
||||||
|
//
|
||||||
public typealias ObjectiveCType = CSBaseDataTransaction
|
// public typealias ObjectiveCType = CSBaseDataTransaction
|
||||||
}
|
//}
|
||||||
|
|||||||
@@ -143,7 +143,7 @@ public final class CSSynchronousDataTransaction: CSBaseDataTransaction {
|
|||||||
|
|
||||||
// MARK: CoreStoreObjectiveCType
|
// MARK: CoreStoreObjectiveCType
|
||||||
|
|
||||||
internal typealias SwiftType = SynchronousDataTransaction
|
public typealias SwiftType = SynchronousDataTransaction
|
||||||
|
|
||||||
public override var bridgeToSwift: SynchronousDataTransaction {
|
public override var bridgeToSwift: SynchronousDataTransaction {
|
||||||
|
|
||||||
@@ -152,21 +152,21 @@ public final class CSSynchronousDataTransaction: CSBaseDataTransaction {
|
|||||||
|
|
||||||
public required init(_ swiftValue: SynchronousDataTransaction) {
|
public required init(_ swiftValue: SynchronousDataTransaction) {
|
||||||
|
|
||||||
super.init(swiftValue)
|
super.init(swiftValue as BaseDataTransaction)
|
||||||
}
|
}
|
||||||
|
|
||||||
public required init(_ swiftValue: BaseDataTransaction) {
|
public required init(_ swiftValue: BaseDataTransaction) {
|
||||||
|
|
||||||
fatalError("init(_:) requires a BaseDataTransaction instance")
|
super.init(swiftValue as! SynchronousDataTransaction)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// MARK: - SynchronousDataTransaction
|
// MARK: - SynchronousDataTransaction
|
||||||
|
|
||||||
extension SynchronousDataTransaction {
|
extension SynchronousDataTransaction: CoreStoreSwiftType {
|
||||||
|
|
||||||
// MARK: CoreStoreSwiftType
|
// MARK: CoreStoreSwiftType
|
||||||
|
|
||||||
internal typealias ObjectiveCType = CSSynchronousDataTransaction
|
public typealias ObjectiveCType = CSSynchronousDataTransaction
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -174,7 +174,7 @@ public final class CSUnsafeDataTransaction: CSBaseDataTransaction {
|
|||||||
|
|
||||||
// MARK: CoreStoreObjectiveCType
|
// MARK: CoreStoreObjectiveCType
|
||||||
|
|
||||||
internal typealias SwiftType = UnsafeDataTransaction
|
public typealias SwiftType = UnsafeDataTransaction
|
||||||
|
|
||||||
public override var bridgeToSwift: UnsafeDataTransaction {
|
public override var bridgeToSwift: UnsafeDataTransaction {
|
||||||
|
|
||||||
@@ -183,21 +183,21 @@ public final class CSUnsafeDataTransaction: CSBaseDataTransaction {
|
|||||||
|
|
||||||
public required init(_ swiftValue: UnsafeDataTransaction) {
|
public required init(_ swiftValue: UnsafeDataTransaction) {
|
||||||
|
|
||||||
super.init(swiftValue)
|
super.init(swiftValue as BaseDataTransaction)
|
||||||
}
|
}
|
||||||
|
|
||||||
public required init(_ swiftValue: BaseDataTransaction) {
|
public required init(_ swiftValue: BaseDataTransaction) {
|
||||||
|
|
||||||
fatalError("init(_:) requires an UnsafeDataTransaction instance")
|
super.init(swiftValue as! UnsafeDataTransaction)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// MARK: - UnsafeDataTransaction
|
// MARK: - UnsafeDataTransaction
|
||||||
|
|
||||||
extension UnsafeDataTransaction {
|
extension UnsafeDataTransaction: CoreStoreSwiftType {
|
||||||
|
|
||||||
// MARK: 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 {
|
do {
|
||||||
|
|
||||||
let result = try closure()
|
let result = try closure()
|
||||||
error.memory = nil
|
if error != nil {
|
||||||
|
|
||||||
|
error.memory = nil
|
||||||
|
}
|
||||||
return result.bridgeToObjectiveC
|
return result.bridgeToObjectiveC
|
||||||
}
|
}
|
||||||
catch let swiftError {
|
catch let swiftError {
|
||||||
|
|
||||||
error.memory = swiftError.bridgeToObjectiveC
|
if error != nil {
|
||||||
|
|
||||||
|
error.memory = swiftError.bridgeToObjectiveC
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -133,12 +139,18 @@ internal func bridge(error: NSErrorPointer, @noescape _ closure: () throws -> Vo
|
|||||||
do {
|
do {
|
||||||
|
|
||||||
try closure()
|
try closure()
|
||||||
error.memory = nil
|
if error != nil {
|
||||||
|
|
||||||
|
error.memory = nil
|
||||||
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
catch let swiftError {
|
catch let swiftError {
|
||||||
|
|
||||||
error.memory = swiftError.bridgeToObjectiveC
|
if error != nil {
|
||||||
|
|
||||||
|
error.memory = swiftError.bridgeToObjectiveC
|
||||||
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -148,12 +160,18 @@ internal func bridge<T>(error: NSErrorPointer, @noescape _ closure: () throws ->
|
|||||||
do {
|
do {
|
||||||
|
|
||||||
let result = try closure()
|
let result = try closure()
|
||||||
error.memory = nil
|
if error != nil {
|
||||||
|
|
||||||
|
error.memory = nil
|
||||||
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
catch let swiftError {
|
catch let swiftError {
|
||||||
|
|
||||||
error.memory = swiftError.bridgeToObjectiveC
|
if error != nil {
|
||||||
|
|
||||||
|
error.memory = swiftError.bridgeToObjectiveC
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -163,12 +181,18 @@ internal func bridge<T: CoreStoreSwiftType>(error: NSErrorPointer, @noescape _ c
|
|||||||
do {
|
do {
|
||||||
|
|
||||||
let result = try closure()
|
let result = try closure()
|
||||||
error.memory = nil
|
if error != nil {
|
||||||
|
|
||||||
|
error.memory = nil
|
||||||
|
}
|
||||||
return result.map { $0.bridgeToObjectiveC }
|
return result.map { $0.bridgeToObjectiveC }
|
||||||
}
|
}
|
||||||
catch let swiftError {
|
catch let swiftError {
|
||||||
|
|
||||||
error.memory = swiftError.bridgeToObjectiveC
|
if error != nil {
|
||||||
|
|
||||||
|
error.memory = swiftError.bridgeToObjectiveC
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user