Created
November 9, 2020 13:44
-
-
Save sjordine/82444de09256a92233dc8f558c876ef5 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 loadCatFact(completion:@escaping (String) -> Void) { | |
| let session = URLSession.shared | |
| if let url = URL(string: "https://catfact.ninja/fact") { | |
| let task = session.dataTask(with: url) { (data, response, error) in | |
| if error == nil, let data = data { | |
| let factData = String(data: data, encoding: .utf8) | |
| completion(factData ?? "") | |
| } | |
| } | |
| task.resume() | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment