I have a property declared in parent class:
var textLabel: UILabel! { get }
Is it possible to make it writable in subclass?
Yes it is possible to make it writable in a subclass. However, since it is a computed property, you will more than likely have to add another stored property to hold the new value you are assigning. I used strings to illustrate below:
class Parent {
var text: String {
get {
return "Parent"
}
}
}
class Child: Parent {
var _text: String = "Child"
override var text: String {
get {
return _text
}
set {
self._text = newValue
}
}
}
let child = Child()
child.text = "New String"
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