Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JohnSundell/efc05e4e49360e98d0e064f22d565da7 to your computer and use it in GitHub Desktop.
Save JohnSundell/efc05e4e49360e98d0e064f22d565da7 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)
}
do {
return try Data(contentsOf: url)
} catch {
throw SearchError.dataLoadingFailed(url)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment