Bill Bill - 1 year ago 98
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 Source
(lldb) e let $layer = unsafeBitCast(0x7fd120f474b0, CALayer.self)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download