The Supportedinterfaceorientations Method Doesn't Override Any Method from Its Superclass

The supportedInterfaceOrientations method doesn't override any method from its superclass

Like this:

override var supportedInterfaceOrientations : UIInterfaceOrientationMask {

...and the rest as you have it.

The general pattern

A lot of Cocoa methods are properties now, so you implement them as override computed variables. So the pattern for moving from seed 3 (or earlier) to seed 4 is:

  • Change func to var

  • Delete ()

  • Change -> to :

This works because a computed variable has a getter function, so the function you were implementing before simply turns into the getter function. And these are read-only properties, so you won't need a setter.

Similarly affected methods are preferredStatusBarStyle, prefersStatusBarHidden, shouldAutorotate, preferredInterfaceOrientationForPresentation, and many others. Look for UIKIT_DEFINE_AS_PROPERTIES in the Objective-C header.

Implications

In the longer term, there are other changes you can make. For example, you can add a setter (dividing your implementation into get and set functions), and thus you can turn your implementation into a facade for a stored property. For example:

private var _orientations = UIInterfaceOrientationMask.portrait
override var supportedInterfaceOrientations : UIInterfaceOrientationMask {
get { return self._orientations }
set { self._orientations = newValue }
}

So now your code has a way to set this value. If you were returning different values at different times, this could make things a lot cleaner.

Further technical notes

Interestingly, this change has no direct effect on existing Objective-C code, because in Objective-C, the new property declaration, @property(nonatomic, readonly) UIInterfaceOrientationMask supportedInterfaceOrientations;, is satisfied by the same method as before:

- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}

The reason is that in Objective-C, a @property(readonly) is merely a promise that a corresponding getter method exists, and that's exactly what this method is. But in Swift, the way to write an Objective-C property's getter method is through a property, that is, through an instance variable. So only Swift code is affected by the change: you have to rewrite your methods as properties.

Method does not override any method from its superclass

New syntax for swift 2.0:

override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
return UIInterfaceOrientationMask.Portrait
}

Check Documentation for more Info.

UIVIevController overriding

supportedInterfaceOrientations is a computed property, not a function:

https://developer.apple.com/documentation/uikit/uiviewcontroller/1621435-supportedinterfaceorientations

so error is correct - there is no such function in superclass.

Replace func with var and () -> with :

Can't Hide Status Bar—Swift 3,

We need to override the property itself on Swift 3 (this is new in Xcode 8 Beta 4):

override var prefersStatusBarHidden: Bool {  
return true
}

updated Swift 5+

override var prefersStatusBarHidden: Bool { true }

for another example also you can get here and here

For more on what this change is and why it's necessary, see Matt's great answer on this.

Can't Hide Status Bar—Swift 3,

We need to override the property itself on Swift 3 (this is new in Xcode 8 Beta 4):

override var prefersStatusBarHidden: Bool {  
return true
}

updated Swift 5+

override var prefersStatusBarHidden: Bool { true }

for another example also you can get here and here

For more on what this change is and why it's necessary, see Matt's great answer on this.

iOS 9 supportedInterfaceOrientations not working

So the issue was that I had defined the allowed orientations in info.plist which apparently overrides anything you do anywhere else throughout the project.

To correct the issue I removed the entries from info.plist and defined them in the project settings. Now everything works as expected.



Related Topics



Leave a reply



Submit