The error is showing up because you're being confused by the two distinct uses of dot notation. The first is ann.coordinate
, where coordinate is a property of whatever object ann is. The second is coordinate.latitude
, where coordinate is a struct and latitude is a field in the struct. Normally one can assign to a property, as in ann.coordinate = aNewCoordinate
. And normally one can assign to a struct field, as in coordinate.latitude = latit
. However, one cannot assign to a field of an anonymous struct returned from a property getter. This will become quite obvious if you remove the property dot notation, as you are then left with [ann coordinate].latitude = latit
, which is clearly wrong. Semantically, you are asking the compiler to construct code that looks similar to
__typeof__(ann.coordinate) __tempCoordinate = ann.coordinate;
__tempCoordinate.latitude = latit;
ann.coordinate = __tempCoordinate;
but this is far out of the scope of the dot syntax and the compiler refuses to generate this code (and rightfully so).