Is there an LLDB command that can cast a raw address into a usable Swift class?
For example:
(lldb) po 0x7df67c50 as MKPinAnnotationView
Objective-C version
po ((MKPinAnnotationView *)0x7df67c50).alpha
For Custom Classes you need to import your project
expr -l Swift -- import MyTestProject
expr -l Swift -- let $vc = unsafeBitCast(0x7fad22c066d0, ViewController.self)
expr -l Swift -- print($vc.view)
As of Xcode 8/Swift 3, here's what worked for me. (This is based off @sfaxon's answer.)
(lldb) expr -l Swift -- import UIKit
(lldb) expr -l Swift -- let $nav = unsafeBitCast(0x1030ff000, to: UINavigationController.self)
The easiest way, swift 4
expr unsafeBitCast(0x7df67c50, to: MKPinAnnotationView.self)
Under Xcode 8.2.1 and Swift 3, the lldb command po or p won't work with the typed variable. You will need to use the swift command print to examine the properties of the typed object instance. (Thanks to cbowns's answer!) E.g.:
expr -l Swift -- import UIKit
expr -l Swift -- let $pin = unsafeBitCast(0x7df67c50, to: MKPinAnnotationView.self)
expr -l Swift -- print($pin.alpha)