Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 629
Bill Avatar asked Jan 18 '15 23:01

Bill


1 Answers

(lldb) e let $layer = unsafeBitCast(0x7fd120f474b0, CALayer.self)
like image 200
Darren Avatar answered Sep 30 '22 19:09

Darren