Created
January 13, 2019 11:26
-
-
Save mwaterfall/0622a7490977373628e0bbc297f8c801 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol UnknownCaseRepresentable: RawRepresentable, CaseIterable { | |
static var unknownCase: Self { get } | |
} | |
extension UnknownCaseRepresentable where Self.RawValue: Equatable { | |
init(rawValue: RawValue) { | |
let value = Self.allCases.first(where: { $0.rawValue == rawValue }) | |
self = value ?? Self.unknownCase | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment