mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-03-13 05:45:32 +01:00
WIP: SaveResult bridge
This commit is contained in:
@@ -148,32 +148,6 @@ public struct Into<T: NSManagedObject>: Hashable {
|
||||
self.configuration = configuration
|
||||
self.inferStoreIfPossible = inferStoreIfPossible
|
||||
}
|
||||
|
||||
internal func upcast() -> Into<NSManagedObject> {
|
||||
|
||||
return Into<NSManagedObject>(
|
||||
entityClass: self.entityClass,
|
||||
configuration: self.configuration,
|
||||
inferStoreIfPossible: self.inferStoreIfPossible
|
||||
)
|
||||
}
|
||||
|
||||
internal func downCast<U: NSManagedObject>(type: U.Type) -> Into<U>? {
|
||||
|
||||
let entityClass: AnyClass = self.entityClass
|
||||
guard entityClass.isSubclassOfClass(U) else {
|
||||
|
||||
return nil
|
||||
}
|
||||
return Into<U>(
|
||||
entityClass: entityClass,
|
||||
configuration: self.configuration,
|
||||
inferStoreIfPossible: self.inferStoreIfPossible
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
// MARK: Private
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ import Foundation
|
||||
}
|
||||
```
|
||||
*/
|
||||
public enum SaveResult {
|
||||
public enum SaveResult: Hashable {
|
||||
|
||||
/**
|
||||
`SaveResult.Success` indicates that the `commit()` for the transaction succeeded, either because the save succeeded or because there were no changes to save. The associated value `hasChanges` indicates if there were saved changes or not.
|
||||
@@ -70,6 +70,21 @@ public enum SaveResult {
|
||||
case Failure(CoreStoreError)
|
||||
|
||||
|
||||
// MARK: Hashable
|
||||
|
||||
public var hashValue: Int {
|
||||
|
||||
switch self {
|
||||
|
||||
case .Success(let hasChanges):
|
||||
return self.boolValue.hashValue ^ hasChanges.hashValue
|
||||
|
||||
case .Failure(let error):
|
||||
return self.boolValue.hashValue ^ error.hashValue
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: Internal
|
||||
|
||||
internal init(hasChanges: Bool) {
|
||||
@@ -97,3 +112,22 @@ extension SaveResult: BooleanType {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - SaveResult: Equatable
|
||||
|
||||
@warn_unused_result
|
||||
public func == (lhs: SaveResult, rhs: SaveResult) -> Bool {
|
||||
|
||||
switch (lhs, rhs) {
|
||||
|
||||
case (.Success(let hasChanges1), .Success(let hasChanges2)):
|
||||
return hasChanges1 == hasChanges2
|
||||
|
||||
case (.Failure(let error1), .Failure(let error2)):
|
||||
return error1 == error2
|
||||
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user