convert array of strings to enums
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
extension Array where Element == String { | |
public func to_enums<T: RawRepresentable>() -> [T] where T.RawValue == String { | |
let wrapped: [T?] = self.map { T(rawValue: $0) } | |
return wrapped.filter { $0 != nil } as! [T] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Then no more filter neither force casting