Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save JohnSundell/4a65f57c5ed47ebf4918c692313609c0 to your computer and use it in GitHub Desktop.
Save JohnSundell/4a65f57c5ed47ebf4918c692313609c0 to your computer and use it in GitHub Desktop.
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