ios – 在Swift 4中无法覆盖扩展声明

ios – 在Swift 4中无法覆盖扩展声明,第1张

概述我最近将我的代码迁移到 Swift 4.我遇到了一个扩展问题,即 Declarations from extensions cannot be overridden yet 我已经阅读了多篇重新评论此问题的帖子.但他们都没有接受下面描述的情景: class BaseCell: UITableViewCell{ //Some code here...}extension BaseCe 我最近将我的代码迁移到 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在扩展中声明.

错误几乎说如果一个函数以这种方式声明,它就不能被覆盖.

该声明对扩展和扩展都有效.

总结

以上是内存溢出为你收集整理的ios – 在Swift 4中无法覆盖扩展声明全部内容,希望文章能够帮你解决ios – 在Swift 4中无法覆盖扩展声明所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1108210.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存