You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would be nice to expose the functionality of UIStoryboardSegue.destinationViewController(ofType:) in a more general way that is useful in different contexts.
For example, lets say you wanted to configure the tabs in a UITabBarController:
finalclassMyTabBarController:UITabBarController{overridefunc viewDidLoad(){
super.viewDidLoad()
nextTab: for tab in viewControllers {
for child in tab.hierarchy {
switch child {caseletfeed as FeedViewController:// configure feed
continue nextTab
caseletprofile as ProfileViewController:// configure profile
continue nextTab
}}}}}
For each tab, this code searches the view controller hierarchy until it finds a matching view controller, then continues to the next tab.
This would be more concise:
for tab in viewControllers {
if let feed = tab.childViewController(ofType:FeedViewController.self){// configure feed}
if let profile = tab.childViewController(ofType: ProfileViewController){// configure profile}}
But has the disadvantage of searching each tab N times, where N is the number of different things you need to configure.
I think there should be a way to encapsulate the first search strategy using a higher-level construct.
The text was updated successfully, but these errors were encountered:
It would be nice to expose the functionality of
UIStoryboardSegue.destinationViewController(ofType:)
in a more general way that is useful in different contexts.For example, lets say you wanted to configure the tabs in a
UITabBarController
:For each tab, this code searches the view controller hierarchy until it finds a matching view controller, then continues to the next tab.
This would be more concise:
But has the disadvantage of searching each tab N times, where N is the number of different things you need to configure.
I think there should be a way to encapsulate the first search strategy using a higher-level construct.
The text was updated successfully, but these errors were encountered: