fileprivate func test() {
guard let w = self.view.window else {
print("no window")
return
}
guard let rootvc = w.rootViewController as? UINavigationController else {
print("no rootvc")
return
}
for vc in rootvc.childViewControllers {
print("CHILD \(vc)")
}
for vc in rootvc.viewControllers {
print("VC \(vc)")
}
}
the code above shows the same. But whats the difference between childViewControllers and viewControllers ?
According to documentation:
public var childViewControllers: [UIViewController] { get }
childViewControllers: An array of view controllers that are children of the current view controller. (read-only). This property does not include any presented view controllers. This property is only intended to be read by an implementation of a custom container view controller.
var viewControllers: [UIViewController] { get set }
viewControllers: The view controllers currently on the navigation stack.
NOTE: A ViewController also have childViewControllers property. but viewControllers property defined in UINavigationController.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With