Created
March 27, 2017 16:44
-
-
Save JohnSundell/4a65f57c5ed47ebf4918c692313609c0 to your computer and use it in GitHub Desktop.
Code sample #4 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 perform(Data(contentsOf: url), | |
orThrow: SearchError.dataLoadingFailed(url)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment