I have created custom class that inherits from UIButton.
In that class I have created a function defined as:
func setChecked(checked:Bool){
self.checked = checked
if checked {
buttonImageView.image = UIImage(named: "radioSelected.png")
} else {
buttonImageView.image = UIImage(named: "radioUnselected.png")
}
}
which was working fine until I updated my xCode to 6.1.3.
Now I keep getting the error message on the function definition line:
Method 'setChecked' with Objective-C selector 'setChecked:' conflicts with setter for 'checked' with the same Objective-C selector
I already tried to make a override it but then I get a error saying that "Method does not override any method from its superclass".
Anyone know how can I correctly solve it?
(I don't want to change the name of my function.)
You have function name conflicting with your property. What about to implement it in a more elegant way with property observing? This explicitly shows how value changes, as well as a side effects for the value changes.
class RadioButton: UIButtom {
var checked: Bool = false {
didSet {
buttonImageView.image = UIImage(named: checked ? "radioSelected.png" : "radioUnselected.png")
}
}
}
It seems that there is a name collision happening. There a few more people with the same issue:
Compiler error: Method with Objective-C selector conflicts with previous declaration with the same Objective-C selector
https://stackoverflow.com/questions/30006724/method-setplayer-with-objective-c-selector-setplayer-conflicts-with-setter
Try renaming your function to something like:
func checkedSetter(checked:Bool){
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With