Created
January 24, 2020 02:31
-
-
Save ryotapoi/b8b85deb82d18e52b4a425465d38ea2f to your computer and use it in GitHub Desktop.
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 where Element == URLQueryItem { | |
func stringValue(for name: String) -> String? { | |
let item = first { $0.name == name } | |
return item?.value | |
} | |
func urlValue(for name: String) -> URL? { | |
guard let string = stringValue(for: name) else { return nil } | |
return URL(string: string) | |
} | |
func intValue(for name: String) -> Int? { | |
guard let string = stringValue(for: name) else { return nil } | |
return Int(string) | |
} | |
func boolValue(for name: String) -> Bool? { | |
guard let string = stringValue(for: name) else { return nil } | |
return Bool(string) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment