情景重现:
在基类WBBaseViewController中的extension中声明了方法setUpUI(),但是在子类WBHomeViewController中的extension中却无法重写该方法,
报错:Declarations in extensions cannot override yet
![](https://img.haomeiwen.com/i2000534/125aea4ce1e610fd.png)
![](https://img.haomeiwen.com/i2000534/1cae6ff3b29a71ce.png)
解决方法
在基类中被重写的方法前面加上 @objc
![](https://img.haomeiwen.com/i2000534/302b5a0e0fdcbd26.png)
问题原因
这个问题在3.0时不会出现,在4.0时,如果重写extension中的方法,就会出现这个报错。
官方在Swift4.0中不推荐重写extension中的方法
网友评论