Skip to content

Instantly share code, notes, and snippets.

@jasonyunjoonpark
Created April 10, 2018 21:02
Show Gist options
  • Save jasonyunjoonpark/b65e583b2b4c8a058e869802976343b1 to your computer and use it in GitHub Desktop.
Save jasonyunjoonpark/b65e583b2b4c8a058e869802976343b1 to your computer and use it in GitHub Desktop.
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
fetchdata()
doSomethingAfterDataFetchIsFinished()
}
func fetchdata() {
//get data
}
func doSomethingAfterDatFetchIsFinished() {
print("data fetch is done")
}
}
@garsdle
Copy link

garsdle commented Apr 10, 2018

import UIKit

class ViewController: UIViewController {
  override func viewDidLoad() {
    super.viewDidLoad()
    fetchdata(onCompletion: { [weak self] in
      self?.doSomethingAfterDataFetchIsFinished()
    })
  }
  
  func fetchdata(onCompletion: ()->()) {
    //get data
    //Make sure to call the on completion block from the completion block of your data fetcher if there is one
    onCompletion()
  }
  
  func doSomethingAfterDataFetchIsFinished() {
    print("data fetch is done")
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment