I'm studying swift to develop macOS app so far.
I wrote a following code to learn property observer.
var x:Int
var y:Int
var oppositePos:coordinatePoint{
get{
coordinatePoint(x: -x, y: -y)
}
set{
x = -newValue.x
y = -newValue.y
}
}
}
I want to implement property observer on opposites property so I changed code as follows :
var x:Int
var y:Int
var oppositePos:coordinatePoint {
willSet{
print("\(oppositePos) is changed to \(newValue)")
}
didSet{
print("\(oldValue) is changed to \(oppositePos)")
}
}
}
after changing code, I ran it but I got following error messages:
- Value type 'coordinatePoint' cannot have a stored property that recursively contains it
- Missing argument for parameter 'oppositePos' in call
My question: property observer is available on this property? if so, what should I change in this code?
if someone give me an advice to fix errors, I'd be very appreciate.
thanks,
c00012