So, I thought I'm quite familiar with Swift, but it turns out, I'm not.
I'm trying to create UINavigationController
and UIViewController
extensions and override some methods to simplify control over device rotation.
So, I found that it's still possible in Swift:
https://stackoverflow.com/a/28220616/982550
But as I don't want to create base UIViewController
class I thought I follow same approach as in Obj-C:
extension UINavigationController {
public override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
return topViewController!.supportedInterfaceOrientations()
}
public override func shouldAutorotate() -> Bool {
return topViewController!.shouldAutorotate()
}
override public func preferredInterfaceOrientationForPresentation() -> UIInterfaceOrientation {
return topViewController!.preferredInterfaceOrientationForPresentation()
}
}
extension UIViewController {
public override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
return .Portrait
}
public override func shouldAutorotate() -> Bool {
return false
}
override public func preferredInterfaceOrientationForPresentation() -> UIInterfaceOrientation {
return .Portrait
}
}
But it doesn't compile with XCode 7.2.1 and Swift 2.1, I got:
: Method 'supportedInterfaceOrientations()' with Objective-C selector 'supportedInterfaceOrientations' conflicts with previous declaration with the same Objective-C selector
I guess there is no way around it, as both class are subclasses of UIViewController
I can't make 2 extensions with same methods?