1
votes

I am trying to implement this function in a textbook and it isn't working. The book is on a different version of swift so that is probably why It isn't working. Im wondering if anyone knows how to figure this out? I am using swift.

    override func supportedInterfaceOrientations() -> Int {
    return Int(UIInterfaceOrientationMask.Portrait.rawValue) |
    Int(UIInterfaceOrientationMask.Landscape.rawValue)
}

Error: Method does not 'override' any method from its superclass. When I remove override, it gives me this error:
Method 'supportedInterfaceOrientations()' with Objective-C selector 'supportedInterfaceOrientations' conflicts with method 'supportedInterfaceOrientations()' from superclass 'UIViewController' with the same Objective-C selector

2
Have you taken a peek at this? iphonedev.tv/blog/2015/6/23/… - Adrian

2 Answers

2
votes

I think the swift2 way to do this is:

override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
    return [UIInterfaceOrientationMask.Portrait, UIInterfaceOrientationMask.Landscape]
}
1
votes

The return type of your function is not the same as that of the method defined in the superclass. UIInterfaceOrientationMask is a swift struct conforming to OptionSetType. While its raw values are of type Int, UIInterfaceOrientationMask is a different type and, because in swift, return types are part of the function signature, you're actually making a new function, not overriding an existing one.

The function you want is

override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask