Last active
August 26, 2020 08:13
-
-
Save elnaqah/6fed004ddccddc8a7e1428c4b06b6e76 to your computer and use it in GitHub Desktop.
This file contains 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 getText(preprocess: @escaping (String) -> String) { | |
self.text = "Requesting..." | |
NetworkHandler.getText { [weak self] (success, text, error) in | |
guard let self = self else { return } | |
guard success, let text = text else { | |
DispatchQueue.main.async { | |
self.text = error ?? "Something went wrong." | |
} | |
return | |
} | |
DispatchQueue.global().async { | |
let string = preprocess(text) | |
DispatchQueue.main.async { | |
self.text = string | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment