mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-02-24 16:45:07 +01:00
WIP: SaveResult bridge
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import CoreData
|
||||
|
||||
|
||||
// MARK: - CSAsynchronousDataTransaction
|
||||
@@ -34,34 +35,20 @@ import Foundation
|
||||
@objc
|
||||
public final class CSAsynchronousDataTransaction: CSBaseDataTransaction {
|
||||
|
||||
// /**
|
||||
// Saves the transaction changes. This method should not be used after the `commit()` method was already called once.
|
||||
//
|
||||
// - parameter completion: the block executed after the save completes. Success or failure is reported by the `SaveResult` argument of the block.
|
||||
// */
|
||||
// public func commit(completion: (result: SaveResult) -> Void = { _ in }) {
|
||||
//
|
||||
// CoreStore.assert(
|
||||
// self.transactionQueue.isCurrentExecutionContext(),
|
||||
// "Attempted to commit a \(typeName(self)) outside its designated queue."
|
||||
// )
|
||||
// CoreStore.assert(
|
||||
// !self.isCommitted,
|
||||
// "Attempted to commit a \(typeName(self)) more than once."
|
||||
// )
|
||||
//
|
||||
// self.isCommitted = true
|
||||
// let group = GCDGroup()
|
||||
// group.enter()
|
||||
// self.context.saveAsynchronouslyWithCompletion { (result) -> Void in
|
||||
//
|
||||
// self.result = result
|
||||
// completion(result: result)
|
||||
// group.leave()
|
||||
// }
|
||||
// group.wait()
|
||||
// }
|
||||
//
|
||||
/**
|
||||
Saves the transaction changes. This method should not be used after the `commit()` method was already called once.
|
||||
|
||||
- parameter completion: the block executed after the save completes. Success or failure is reported by the `CSSaveResult` argument of the block.
|
||||
*/
|
||||
@objc
|
||||
public func commit(completion: ((result: CSSaveResult) -> Void)?) {
|
||||
|
||||
self.swift.commit { (result) in
|
||||
|
||||
completion?(result: result.objc)
|
||||
}
|
||||
}
|
||||
|
||||
// /**
|
||||
// Begins a child transaction synchronously where NSManagedObject creates, updates, and deletes can be made. This method should not be used after the `commit()` method was already called once.
|
||||
//
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import CoreData
|
||||
|
||||
|
||||
// MARK: - CSBaseDataTransaction
|
||||
|
||||
@@ -255,6 +255,7 @@ public final class CSDataStack: NSObject, CoreStoreBridge {
|
||||
internal init(_ swiftObject: DataStack) {
|
||||
|
||||
self.swift = swiftObject
|
||||
super.init()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -107,6 +107,7 @@ public final class CSInMemoryStore: NSObject, CSStorageInterface, CoreStoreBridg
|
||||
public required init(_ swiftObject: InMemoryStore) {
|
||||
|
||||
self.swift = swiftObject
|
||||
super.init()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,11 +2,29 @@
|
||||
// CSInto.swift
|
||||
// CoreStore
|
||||
//
|
||||
// Created by John Estropia on 2016/03/24.
|
||||
// Copyright © 2016年 John Rommel Estropia. All rights reserved.
|
||||
// Copyright © 2016 John Rommel Estropia
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
import Foundation
|
||||
import CoreData
|
||||
|
||||
|
||||
// MARK: - CSInto
|
||||
|
||||
@@ -184,6 +184,7 @@ public final class CSSQLiteStore: NSObject, CSLocalStorage, CoreStoreBridge {
|
||||
public required init(_ swiftObject: SQLiteStore) {
|
||||
|
||||
self.swift = swiftObject
|
||||
super.init()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
76
Sources/ObjectiveC/CSSaveResult.swift
Normal file
76
Sources/ObjectiveC/CSSaveResult.swift
Normal file
@@ -0,0 +1,76 @@
|
||||
//
|
||||
// CSSaveResult.swift
|
||||
// CoreStore
|
||||
//
|
||||
// Copyright © 2016 John Rommel Estropia
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import CoreData
|
||||
|
||||
|
||||
// MARK: - CSSaveResult
|
||||
|
||||
/**
|
||||
The `CSSaveResult` serves as the Objective-C bridging type for `SaveResult`.
|
||||
*/
|
||||
@objc
|
||||
public final class CSSaveResult: NSObject, CoreStoreBridge {
|
||||
|
||||
|
||||
|
||||
// MARK: NSObject
|
||||
|
||||
public override var hash: Int {
|
||||
|
||||
return self.swift.hashValue
|
||||
}
|
||||
|
||||
public override func isEqual(object: AnyObject?) -> Bool {
|
||||
|
||||
guard let object = object as? CSSaveResult else {
|
||||
|
||||
return false
|
||||
}
|
||||
return self.swift == object.swift
|
||||
}
|
||||
|
||||
|
||||
// MARK: CoreStoreBridge
|
||||
|
||||
internal let swift: SaveResult
|
||||
|
||||
public required init(_ swiftObject: SaveResult) {
|
||||
|
||||
self.swift = swiftObject
|
||||
super.init()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - SaveResult
|
||||
|
||||
extension SaveResult: CoreStoreBridgeable {
|
||||
|
||||
// MARK: CoreStoreBridgeable
|
||||
|
||||
internal typealias ObjCType = CSSaveResult
|
||||
}
|
||||
Reference in New Issue
Block a user