Last active
January 14, 2022 10:13
-
-
Save smrfeld/c0780168c5cf819f200973f6f211dd57 to your computer and use it in GitHub Desktop.
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