Skip to content
Snippets Groups Projects
Commit 747e6c60 authored by Dariusz Rybicki's avatar Dariusz Rybicki
Browse files

Add Stored.tryGet extension

parent 4a38e1cd
No related branches found
No related tags found
3 merge requests!102Release 1.0.0,!62Messenger example - account deletion,!61Messenger example - account deletion
......@@ -31,6 +31,23 @@ private final class Memory<Value> {
var value: Value
}
extension Stored {
public struct MissingValueError: Error, Equatable {
public init(typeDescription: String) {
self.typeDescription = typeDescription
}
public var typeDescription: String
}
public func tryGet<T>() throws -> T where Value == Optional<T> {
guard let value = get() else {
throw MissingValueError(typeDescription: "\(Self.self)")
}
return value
}
}
extension Stored {
public static func unimplemented(placeholder: Value) -> Stored<Value> {
Stored<Value>(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment