Created
March 11, 2018 15:34
-
-
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)
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
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