Created
July 25, 2015 08:39
-
-
Save BasThomas/a70aa9eb46eab3a08f95 to your computer and use it in GitHub Desktop.
LowercaseInitializable
This file contains 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
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