Can I implement this in Swift with Extensions without the need to inheritance?. I get this error Extensions May not contain Stored properties
extension UIB
Extensions cannot add stored properties. From the docs (Computed Properties section):
Note
Extensions can add new computed properties, but they cannot add stored properties, or add property observers to existing properties.
If you have a need for stored properties, you should create a subclass, like so:
class CustomButton : UIButton
{
@IBInspectable var borderWidth : CGFloat
{
didSet{
layer.borderWidth = borderWidth
}
}
}