mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-03-30 14:21:49 +02:00
make CoreStoreError dynamicc initializer public
This commit is contained in:
@@ -79,6 +79,29 @@ public enum CoreStoreError: Error, CustomNSError, Hashable {
|
|||||||
*/
|
*/
|
||||||
case persistentStoreNotFound(entity: DynamicObject.Type)
|
case persistentStoreNotFound(entity: DynamicObject.Type)
|
||||||
|
|
||||||
|
/**
|
||||||
|
Casts any `Error` to a known `CoreStoreError`, or wraps it in `CoreStoreError.internalError(NSError:)`.
|
||||||
|
*/
|
||||||
|
public init(_ error: Error?) {
|
||||||
|
|
||||||
|
guard let error = error else {
|
||||||
|
|
||||||
|
self = .unknown
|
||||||
|
return
|
||||||
|
}
|
||||||
|
switch error {
|
||||||
|
|
||||||
|
case let error as CoreStoreError:
|
||||||
|
self = error
|
||||||
|
|
||||||
|
case let error as NSError:
|
||||||
|
self = .internalError(NSError: error)
|
||||||
|
|
||||||
|
default:
|
||||||
|
self = .unknown
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// MARK: CustomNSError
|
// MARK: CustomNSError
|
||||||
|
|
||||||
@@ -253,29 +276,6 @@ public enum CoreStoreError: Error, CustomNSError, Hashable {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// MARK: Internal
|
|
||||||
|
|
||||||
internal init(_ error: Error?) {
|
|
||||||
|
|
||||||
guard let error = error else {
|
|
||||||
|
|
||||||
self = .unknown
|
|
||||||
return
|
|
||||||
}
|
|
||||||
switch error {
|
|
||||||
|
|
||||||
case let error as CoreStoreError:
|
|
||||||
self = error
|
|
||||||
|
|
||||||
case let error as NSError:
|
|
||||||
self = .internalError(NSError: error)
|
|
||||||
|
|
||||||
default:
|
|
||||||
self = .unknown
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user