Created
September 9, 2022 19:04
-
-
Save antonio081014/26804a195fff562c799f94d8322e9860 to your computer and use it in GitHub Desktop.
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 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