Skip to content

Instantly share code, notes, and snippets.

@elnaqah
Last active August 26, 2020 08:13
Show Gist options
  • Save elnaqah/6fed004ddccddc8a7e1428c4b06b6e76 to your computer and use it in GitHub Desktop.
Save elnaqah/6fed004ddccddc8a7e1428c4b06b6e76 to your computer and use it in GitHub Desktop.
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