大佬教程收集整理的这篇文章主要介绍了ios – Swift Extension – 方法与先前使用相同Objective-C选择器的声明冲突,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
码:
extension UIViewController { public override func shouldAutorotate() -> Bool { return false } public override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask { return UIInterfaceOrientationMask.PorTrait } }
错误:
@H_331_9@method 'shouldAutorotate()' with Objective-C SELEctor 'shouldAutorotate' conflicts with prev@L_874_7@s declaration with the same Objective-C SELEctor Method does not override any method from its superclass Method 'supportedInterfaceOrientations()' with Objective-C SELEctor 'supportedInterfaceOrientations' conflicts with prev@L_874_7@s declaration with the same Objective-C SELEctor
在这里,我错过了什么?
我正在使用Xcode 7.3.1和Swift 2.x.
编辑:
从Answers下面,我知道我们不能像在Objective C Categories中那样在Swift扩展中改变运行时类的现有方法的行为.在这里,我应该创建一个将覆盖方法的基类,@R_659_10675@用我的所有ViewControllers作为新基类的子类作为父类.
但就我而言,我想改变所有“shouldAutorotate”方法的行为,包括第三方框架UIViewController.在上面的例子中,我不能强制所有第三方框架UIviewControllers成为我的基类的子类.在Objective C中,我可以做到这一点.
class UIViewController : UIResponder { public func shouldAutorotate() -> Bool { return true } public func shouldAutorotate() -> Bool { return false } }
哪一个获胜?这就是你被警告的冲突.
如果您需要覆盖您的视图控制器的方法,则需要在子类中执行此操作,而不是扩展.
Ninja编辑:这可能在Objective-C中可以做到,但那里是一个编程错误.如果类别与主类重复方法,则使用哪个定义是未定义的.见this SO post和backing Apple documentation.
以上是大佬教程为你收集整理的ios – Swift Extension – 方法与先前使用相同Objective-C选择器的声明冲突全部内容,希望文章能够帮你解决ios – Swift Extension – 方法与先前使用相同Objective-C选择器的声明冲突所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。