Bill Bill - 9 days ago 6
Swift Question

When debugging Swift code, can I get a typed reference to an object given just its address?

When debugging Objective-C code in LLDB, I often create variables that refer to objects in memory using just their address. For example:

(lldb) po self.view
<UIView: 0x7ff5f7a18430; frame = (0 64; 320 504); autoresize = W+H; layer = <CALayer: 0x7ff5f7a192e0>>
(lldb) e CALayer* $layer = (CALayer*) 0x7ff5f7a192e0
(lldb) e $layer.borderWidth
(CGFloat) $17 = 0


Given just an object's type and its address in memory, I'm able to inspect and manipulate it.

Is this impossible when debugging Swift code?

Answer
(lldb) e let $layer = unsafeBitCast(0x7fd120f474b0, CALayer.self)