Skip to content

Instantly share code, notes, and snippets.

@jasonyunjoonpark
Created April 28, 2018 20:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jasonyunjoonpark/d52cd56847545c9f050b7c4f85f1953e to your computer and use it in GitHub Desktop.
Save jasonyunjoonpark/d52cd56847545c9f050b7c4f85f1953e to your computer and use it in GitHub Desktop.
completion handler for a function that takes a parameter
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
DispatchQueue.global(qos: .userInteractive).async {
//Background thread
func countTo(10) //not sure how to wait for this to be finished before updating the button label on main thread
DispatchQueue.main.async {
//Update Button Label after count is finished
}
}
}
func countTo(number: Int) {
var counter = 0
while counter < number {
counter += 1
print(counter)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment