TIMEX
TIMEX

Reputation: 271684

How can I override this Swift property?

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


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

I'm getting an error:

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

Upvotes: 5

Views: 5173

Answers (2)

user212514
user212514

Reputation: 3130

The two different declarations of rightButtonColor have different types. It compiles cleanly if you make sure they're the exact same type:

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

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

Upvotes: -2

Pushpa Y
Pushpa Y

Reputation: 1010

Try like this:

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

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

Upvotes: 7

Related Questions