Extensions May not contain Stored properties

前端 未结 3 1747
后悔当初
后悔当初 2020-12-24 05:30

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         


        
3条回答
  •  时光取名叫无心
    2020-12-24 05:57

    You can override the setter/getter so that it isn't a stored property and just forwards the set/get to the layer.

    extension UIButton {
        @IBInspectable var borderWidth : CGFloat {
            set {
                layer.borderWidth = newValue
            }
    
            get {
                return layer.borderWidth
            }
        }
    }
    

提交回复
热议问题