I was playing around with trying to get/set a computed property of an object through a pointer to that property. I\'ve included the code snippet and output below.
The g
The Swift language definition does not require it to not move (or reuse) the memory used by class object instance properties, once outside the block or scope where unsafe pointers and other internal references are valid.
So, in your second and third case, the object (or some of its properties) has likely been moved and you are examining and (dangerously) changing memory where the object used to be, and where part of some completely different type of object might currently be, through a stale (and thus very unsafe) pointer.
So the Swift compiler (which knows when and where it moved stuff) knows how to read and write the property inside the instance. But you (via stale pointers) do not.
Added: If you want to do this type of stuff, then allocate (and manage) the memory yourself (which is possible in Swift).