Joseph K Joseph K - 1 month ago 100
Swift Question

prefersStatusBarHidden, preferredStatusBarStyle properties in Swift 3

Starting Swift 3 / iOS 10, methods such as preferredStatusBarStyle and prefersStatusBarHidden became:

@available(iOS 7.0, *)
open var preferredStatusBarStyle: UIStatusBarStyle { get }

@available(iOS 7.0, *)
open var prefersStatusBarHidden: Bool { get }

As such existing code that used to override the methods no longer builds. Given these properties are readonly, how can you assign them a value / override them?


You need to learn that in Swift (since the first public beta pre-1.0), you can override properties. Read-only properties can be overridden like this:

override var preferredStatusBarStyle: UIStatusBarStyle {
    return yourPreferredStatusBarStyle