ios - 如何覆盖此 Swift 属性?

标签 ios swift

class Base: UIViewController {
    var rightButtonColor: UIColor = UIColor.blueColor()
}


class SecondViewController: Base {    
    override var rightButtonColor: UIColor {
        return UIColor.redColor() 
    }
}

我收到一个错误:

Getter for 'rightButtonColor' with Objective-C selector 'rightButtonColor' conflicts with getter for 'rightButtonColor' from superclass 'Base' with the same Objective-C selector

最佳答案

像这样尝试:

class Base: UIViewController {
    var rightButtonColor: UIColor {
        return UIColor.blueColor()
    }
}

class SecondViewController: Base {
    override var rightButtonColor: UIColor {
        return UIColor.redColor()
    }
}

关于ios - 如何覆盖此 Swift 属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37405351/

相关文章:

ios - 如何从 NSDictionary 获取 IndexPath

c - 如何从 UnsafeMutableRawPointer 获取页对齐地址?

iOS 后台 App Fetch 不工作

objective-c - iOS 模拟器上的照片库

ios - 子对象上的 NSDictionary 谓词过滤器

swift - 含 UIColor 扩展名的 'methodName' 使用不明确

ios - 如何在 Swift 中获取唯一的设备 ID?

ios - 继续记录丢失的服务器连接以获取 kct 连接无效通知

ios - 状态栏在仅纵向 View 中旋转后为横向

ios - 如何创建 STPCard Stripe ios?