Code below. Why does the "Overriding declaration requires an 'override' keyword" error occur? Isn't this the "Swift" way of providing getters and setters to properties?
class TestClass : UICollectionViewCell {
var _selected = false
var selected : Bool {
get {
return _selected
}
set {
_selected = newValue
selectedView.hidden = !_selected
}
}
}
First,don't use _selected in Swift.It's Objective-C style.
Second, and override keyword before var selected : Bool because its super has declared a property with the same name.
Update: This is a store value,you don't need to do anything to get its value because swift will store it automaticlly.
override var selected : Bool {
get {
return super.selected
}
set {
selectedView.hidden = !newValue
}
}
Or use didSet:
override var selected : Bool {
didSet {
selectedView.hidden = !selected
}
}
Use store value to keep a persistence value.Use computing(which has a getter) to get real-time value.
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