Created
October 15, 2021 13:14
-
-
Save DominikPalo/6f425c90e69cf3209cbae6d0cef24b4c to your computer and use it in GitHub Desktop.
A Swift extension for an array containing name-value tuples to get the value of the first tuple found by name
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
fileprivate extension Array where Element == (String, String) { | |
func firstValue(name: String) -> String? { | |
if let tuple = self.first(where: {$0.0 == name}) { | |
return tuple.1 | |
} | |
return nil | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment