I wrote a custom UIView and I found a strange problem. I think this is due to a very fundamental concept, but I just donβt understand it, sigh .....
class ArrowView: UIView { override func draw(_ rect: CGRect) { let arrowPath = UIBezierPath.bezierPathWithArrowFromPoint(startPoint: CGPoint(x:bounds.size.width/2,y:bounds.size.height/3), endPoint: CGPoint(x:bounds.size.width/2, y:bounds.size.height/3*2), tailWidth: 8, headWidth: 24, headLength: 18) let fillColor = UIColor(red: 0.00, green: 0.59, blue: 1.0, alpha: 1.0) fillColor.setFill() arrowPath.fill() } }
this code works fine, but if I grab this line from the undo function, it does not compile. The error says that I cannot use the bounds property.
let arrowPath = UIBezierPath.bezierPathWithArrowFromPoint(startPoint: CGPoint(x:bounds.size.width/2,y:bounds.size.height/3), endPoint: CGPoint(x:bounds.size.width/2, y:bounds.size.height/3*2), tailWidth: 8, headWidth: 24, headLength: 18)
Unable to use instance member bounds in property initializer; Property initializers start before "self".
I do not understand why I can not use these restrictions from func draw
source share