我最近将我的代码迁移到
Swift 4.我遇到了一个扩展问题,即
Declarations from extensions cannot be overridden yet
我已经阅读了多篇重新评论此问题的帖子.但他们都没有接受下面描述的情景:
class BaseCell: UITableViewCell { //Some code here... } extension BaseCell { func isValid() -> String? { //Some code here... } } class SampleCell: BaseCell { //Some code here... override func isValid() -> String? //ERROR..!!! { //Some code here... } }
根据Apple的说法,
Extensions can add new functionality to a type,but they cannot override existing functionality.
但在上面的场景中,我没有在扩展中覆盖方法isValid().它在SampleCell类定义本身中被重写.不过,它正在给出错误.
解决方法
But in the above scenario,I am not overriding the method
isValid()
in an extension.
isValid在扩展中声明.
错误几乎说如果一个函数以这种方式声明,它就不能被覆盖.
该声明对扩展和扩展都有效.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。