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()
    }
}
点赞