Example 1
Each controller is able to hide / show the bar individually. However, if you write a generic extension for all view controllers, this basically means you are switching it off for all views. This is actually not different from switching it off entirely for the whole app via Info.plist
// switch off statusbar for the entire app (all views)
extension UIViewController {
func prefersStatusBarHidden() -> Bool {
return true
}
}
// switch off statusbar for only specific views
class MyViewController: UIViewController {
..
override func prefersStatusBarHidden() -> Bool {
return true
}
}
Example 2
You need to know if your ViewController is included in a container (such as UINavigationController) in that case the NavigationController takes control of the StatusBar. You might to write a solution where the navigation controller always gives the control to the topviewcontroller in this case: see iphoneX not call prefersStatusBarHidden
NavigationView {
}
.statusBar(hidden: true)
Example 4
You can set the status also once for the whole app. That is done in the Info.plist file
<key>UIStatusBarHidden</key>
<true/>
Example 5
You can setup the setting for the whole app but have it differently for each target. Thats done here.
Status Bar Style: Hide status bar (in Target Settings)