goodbye ObjectiveC

This commit is contained in:
John Estropia
2021-09-22 20:04:58 +09:00
parent bf10f4668c
commit 9a026afe40
110 changed files with 1060 additions and 9816 deletions

View File

@@ -29,162 +29,83 @@ import CoreData
// MARK: - CSSetupResult
/**
The `CSSetupResult` serves as the Objective-C bridging type for `SetupResult`.
- SeeAlso: `SetupResult`
*/
@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.")
@available(*, unavailable, message: "CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.")
@objc
public final class CSSetupResult: NSObject {
/**
`YES` if adding the `CSStorageInterface` to the `CSDataStack` succeeded, `NO` otherwise.
*/
@objc
public var isSuccess: Bool {
return self.storage != nil
fatalError()
}
/**
`YES` if adding the `CSStorageInterface` to the `CSDataStack` failed, `NO` otherwise. When `YES`, the `error` property returns the actual `NSError` for the failure.
*/
@objc
public var isFailure: Bool {
return self.storage == nil
fatalError()
}
/**
A `CSStorageInterface` instance if the `commit` operation for the transaction succeeded. Returns `nil` otherwise.
*/
@objc
public let storage: CSStorageInterface?
/**
The `NSError` for a failed `commit` operation, or `nil` if the `commit` succeeded
*/
@objc
public let error: NSError?
/**
If the result was a success, the `success` block is executed with the `CSStorageInterface` instance that was added to the `CSDataStack`. If the result was a failure, the `failure` block is executed with an `NSError` argument pertaining to the actual error.
The blocks are executed immediately as `@noescape` and will not be retained.
- parameter success: the block to execute on success. The block passes a `CSStorageInterface` instance that was added to the `CSDataStack`.
- parameter failure: the block to execute on failure. The block passes an `NSError` argument that pertains to the actual error.
*/
@objc
public func handleSuccess(_ success: (_ storage: CSStorageInterface) -> Void, failure: (_ error: NSError) -> Void) {
if let storage = self.storage {
success(storage)
}
else {
failure(self.error!)
}
fatalError()
}
/**
If the result was a success, the `success` block is executed with a `BOOL` argument that indicates if there were any changes made. If the result was a failure, this method does nothing.
The block is executed immediately as `@noescape` and will not be retained.
- parameter success: the block to execute on success. The block passes a `BOOL` argument that indicates if there were any changes made.
*/
@objc
public func handleSuccess(_ success: (_ storage: CSStorageInterface) -> Void) {
guard let storage = self.storage else {
return
}
success(storage)
fatalError()
}
/**
If the result was a failure, the `failure` block is executed with an `NSError` argument pertaining to the actual error. If the result was a success, this method does nothing.
The block is executed immediately as `@noescape` and will not be retained.
- parameter failure: the block to execute on failure. The block passes an `NSError` argument that pertains to the actual error.
*/
@objc
public func handleFailure(_ failure: (_ error: NSError) -> Void) {
guard let error = self.error else {
return
}
failure(error)
fatalError()
}
// MARK: NSObject
public override var hash: Int {
if let storage = self.storage {
return self.isSuccess.hashValue ^ ObjectIdentifier(storage).hashValue
}
return self.isSuccess.hashValue ^ self.error!.hashValue
fatalError()
}
public override func isEqual(_ object: Any?) -> Bool {
guard let object = object as? CSSetupResult else {
return false
}
return self.storage === object.storage
&& self.error == object.error
fatalError()
}
public override var description: String {
return "(\(String(reflecting: Self.self))) \(self.bridgeToSwift.coreStoreDumpString)"
fatalError()
}
// MARK: CoreStoreObjectiveCType
public required init<T>(_ swiftValue: SetupResult<T>) where T: CoreStoreSwiftType, T.ObjectiveCType: CSStorageInterface {
switch swiftValue {
case .success(let storage):
self.storage = storage.bridgeToObjectiveC
self.error = nil
case .failure(let error):
self.storage = nil
self.error = error.bridgeToObjectiveC
}
self.bridgeToSwift = swiftValue
super.init()
fatalError()
}
// MARK: Private
private let bridgeToSwift: CoreStoreDebugStringConvertible
}
// MARK: - SetupResult
@available(*, deprecated, message: "CoreStore Objective-C API will be removed soon.")
@available(*, unavailable, message: "CoreStore Objective-C is now obsoleted in preparation for Swift concurrency.")
extension SetupResult where Success: StorageInterface, Success: CoreStoreSwiftType, Success.ObjectiveCType: CSStorageInterface, Failure == CoreStoreError {
// MARK: CoreStoreSwiftType
public var bridgeToObjectiveC: CSSetupResult {
return CSSetupResult(self)
fatalError()
}
}