metatext/Shared/Model/Unknowable.swift

14 lines
343 B
Swift
Raw Normal View History

2020-08-07 01:41:59 +00:00
// Copyright © 2020 Metabolist. All rights reserved.
import Foundation
protocol Unknowable: RawRepresentable, CaseIterable where RawValue: Equatable {
2020-08-07 03:57:52 +00:00
static var unknownCase: Self { get }
2020-08-07 01:41:59 +00:00
}
extension Unknowable {
init(rawValue: RawValue) {
2020-08-07 03:57:52 +00:00
self = Self.allCases.first { $0.rawValue == rawValue } ?? Self.unknownCase
2020-08-07 01:41:59 +00:00
}
}