metatext-app-ios-iphone-ipad/Shared/Model/Unknowable.swift

18 lines
456 B
Swift
Raw Normal View History

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