jarrodparkes jarrodparkes - 5 months ago 46
iOS Question

LLDB (Swift): Casting Raw Address into Usable Type

Is there an LLDB command that can cast a raw address into a usable Swift class?

For example:

(lldb) po 0x7df67c50 as MKPinAnnotationView

I know that this address points to a MKPinAnnotationView, but it is not in a frame that I can select. But, I want to cast the raw address into a MKPinAnnotationView so that I can examine its properties. Is this possible?


You can use Swift's unsafeBitCast function to cast an address to an object instance:

(lldb) e let $pin = unsafeBitCast(0x7df67c50, MKPinAnnotationView.self)
(lldb) po $pin

Then you can work with $pin as usual – access properties, call methods, etc.

Check out this article for more information: Swift Memory Dumping.