Hiding a tab in a tab bar in iOS (Swift)

As the title states, how do you hide/show a tab in a tab bar where a tab bar controller is programmatically?

Or is there a better way to do this, since I want to show a certain tab containing a certain view depending on the user that logs in.


Solution 1:

Assuming that you have a subclass of UITabBarController:

final class YourSubClass: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        viewControllers?.remove(at: 0) // remove the first tab, tab index starts with 0
    }

}