Skip to content

Instantly share code, notes, and snippets.

@mwaterfall
Created January 13, 2019 11:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mwaterfall/0622a7490977373628e0bbc297f8c801 to your computer and use it in GitHub Desktop.
Save mwaterfall/0622a7490977373628e0bbc297f8c801 to your computer and use it in GitHub Desktop.
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