Skip to content

Instantly share code, notes, and snippets.

@BasThomas
Created July 25, 2015 08:39
Show Gist options
  • Save BasThomas/a70aa9eb46eab3a08f95 to your computer and use it in GitHub Desktop.
Save BasThomas/a70aa9eb46eab3a08f95 to your computer and use it in GitHub Desktop.
LowercaseInitializable
public protocol LowercaseInitializable {
static var allValues: [Self] { get }
init?(rawValue: String)
}
extension LowercaseInitializable {
public init?(rawValue: String) {
let value = Self.allValues.filter { $0.rawValue.lowercaseString == rawValue.lowercaseString } // ERROR: Cannot invoke 'filter' with argument list of type '((_) -> _)'
if let state = value.first {
self = state
} else {
return nil
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment