Suppose I create a variable @IBInspectablein a base class@IBDesignable .
Now the attribute does not make the property checked in the derived class. It is clear in design; you want to create a derived class that sets the base attributes in accordance with its own logic and prevents the user from touching them.
However, suppose I want the same attributes to be checked in a derived class . The problem is that it is @IBInspectableused only with variable definitions, so I need to redefine the variable even if the definition is already provided (that when I skipped Objective-C: you can change the class interface without touching if you knew what you were doing).
This has the following drawback: you cannot override the base stored variable, and you need to provide an explicit getter and setter. Therefore, the cleanest code I came up with is this:
@IBInspectable override var borderWidth: CGFloat {
get {
return super.borderWidth
}
set {
super.borderWidth = newValue
}
}
@IBInspectable var borderWidth: CGFloat {
set {
layer.borderWidth = newValue
}
get {
return layer.borderWidth
}
}
Question: is there a shorthand syntax?
(If not, and if other people like the idea, I will probably send a radar to Apple wizards.)
source
share