Skip to content

Instantly share code, notes, and snippets.

@antonio081014
Created September 9, 2022 19:04
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 antonio081014/26804a195fff562c799f94d8322e9860 to your computer and use it in GitHub Desktop.
Save antonio081014/26804a195fff562c799f94d8322e9860 to your computer and use it in GitHub Desktop.
func load(from url: URL, completion: @escaping (Result<Data, Error>) -> Void) {
DispatchQueue.global().async {
do {
let data = try Data(contentsOf: url)
DispatchQueue.main.async {
completion(.success(data))
}
} catch {
DispatchQueue.main.async {
completion(.failure(error))
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment