【问题标题】:Override Objective C Methods in Swift File覆盖 Swift 文件中的 Objective C 方法
【发布时间】:2016-11-09 05:41:24
【问题描述】:

我在 Objective C 中有一些方法。

我从目标 C 超类创建了一个子类。

现在我想在我的 Swift 类中重写 Objective C 超类方法。

我的代码:

@objc class JobBusinessTableViewCell: AdItemTableViewCell {

    override func commonInit() {
        super.commonInit()
    }

   override func updateWithAd(ads: ResponseSimpleAd) {
        super.updateWithAd(ads)
    }
}

这里的AdItemTableViewCell 是一个Objective C 超类。

我想在 Swift 中重写 updateWithAd 方法。

我该怎么做?

【问题讨论】:

    标签: objective-c swift


    【解决方案1】:

    我找到了答案..但看起来很奇怪..

    工作代码:

     public final override func update(with ad : ResponseSimpleAd) {
            super.update(with: ad)
    
    }
    

    我不明白 swift 中的方法名称更改..但按预期工作...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-17
      相关资源
      最近更新 更多