0

I'm thinking of defining:

extension UIViewController {
  override var prefersStatusBarHidden: Bool {
    return true
  }
}

Does this also work for subclasses, like:

class UINavigationController: UIViewController {      
  override var prefersStatusBarHidden: Bool {
    return false
  }
}

Is the property true or false? Does the extension take priority over the subclass or the other way around?

Kartick Vaddadi
  • 4,818
  • 6
  • 39
  • 55
  • From the Swift book on extensions: *“Extensions can add new functionality to a type, but they cannot override existing functionality.”* – rmaddy Mar 11 '17 at 17:00
  • 1
    Did you try it? What did you find? – Hamish Mar 11 '17 at 17:12
  • Related: [Overriding methods in Swift extensions](http://stackoverflow.com/questions/38213286/overriding-methods-in-swift-extensions) – Hamish Mar 11 '17 at 17:13
  • 1
    The premise of the question is invalid. You can't 'override' the property `prefersStatusBarHidden` in a `UIViewController` extension, because `prefersStatusBarHidden` is a `UIViewController` property, not a superclass property - not to mention that you can't override in extensions. So there's only one way to do it (with a subclass). – Søren Mortensen Mar 11 '17 at 20:53
  • Thanks, @SørenMortensen, you're right. This seems to be different from Objective-C. – Kartick Vaddadi Mar 12 '17 at 01:40

0 Answers0