I'm wondering why ios devs use closure to pass single value if we can just pass the value itself? I've some doubts but I need some clear reasoning on why do it? I've seen it used commonly as providers. Here is an example
func navigate(_ property: Int, navProvider: (() -> UINavigationController)) {
let vc = MyVC()
vc.property = property
let navController = navProvider()
navController.push(vc)
}
what will happen if we changed this code to the below?
func navigate(_ property: Int, navController: UINavigationController) {
let vc = MyVC()
vc.property = property
navController.push(vc)
}
Thanks!
Aucun commentaire:
Enregistrer un commentaire