Skip to content

Instantly share code, notes, and snippets.

@MoathOthman
Created March 11, 2018 15:34
Show Gist options
  • Save MoathOthman/7eab5c4354c7522f84cfcac7266cc2e5 to your computer and use it in GitHub Desktop.
Save MoathOthman/7eab5c4354c7522f84cfcac7266cc2e5 to your computer and use it in GitHub Desktop.
On View did load (when u need to execute some code after view is loaded in uiviewcontroller)
class SuperViewController: UIViewController {
typealias VoidClosure = () -> Void
private var onViewDidLoad: [VoidClosure] = []
// public
func addOnViewdidLoad(block: @escaping VoidClosure) {
if isViewLoaded {
block()
} else {
self.onViewDidLoad.append(block)
}
}
}
// example usage ,on a subclass
addOnViewDidLoad {
self.priceLabel.text = "230"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment