Last active
March 27, 2017 16:39
-
-
Save JohnSundell/ed6ea256dcf94da1678f81a28c6d0bca to your computer and use it in GitHub Desktop.
Code sample #1 from https://medium.com/@johnsundell/providing-a-unified-swift-error-api-3642cd3173f0
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
func loadSearchData(matching query: String) throws -> Data { | |
let urlString = "https://my.api.com/search?q=\(query)" | |
guard let url = URL(string: urlString) else { | |
throw SearchError.invalidQuery(query) | |
} | |
return try Data(contentsOf: url) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment