class Base: UIViewController {
var rightButtonColor: UIColor = UIColor.blueColor()
}
class SecondViewController: Base {
override var rightButtonColor: UIColor {
return UIColor.redColor()
}
}
我收到了一个错误:
使用Objective-C选择器获取'rightButtonColor' 'rightButtonColor'与来自'rightButtonColor'的getter冲突 超类'Base'具有相同的Objective-C 选择
答案 0 :(得分:5)
试试这样:
class Base: UIViewController {
var rightButtonColor: UIColor {
return UIColor.blueColor()
}
}
class SecondViewController: Base {
override var rightButtonColor: UIColor {
return UIColor.redColor()
}
}
答案 1 :(得分:-2)
rightButtonColor
的两个不同声明有不同的类型。如果你确定它们是完全相同的类型,它会干净地编译:
class Base: UIViewController {
var rightButtonColor: UIColor {
return UIColor.blueColor()
}
}
class SecondViewController: Base {
override var rightButtonColor: UIColor {
return UIColor.redColor()
}
}