Created
March 31, 2021 07:56
-
-
Save msewell/6e7f70c78662a4c0600b28b5b574b918 to your computer and use it in GitHub Desktop.
First element in array matching type
This file contains hidden or 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 { | |
func first<T>(_ matchingType: T.Type) -> T? { | |
first(where: { $0 is T }) as? T | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment