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?
 asked Jan 18, 2015 at 23:57
 
 
 
 Bill 
 
 46k25 gold badges128 silver badges218 bronze badges
 
 1 Answer 1
(lldb) e let $layer = unsafeBitCast(0x7fd120f474b0, CALayer.self)
 Sign up to request clarification or add additional context in comments.
 
 
 
 4 Comments
Bill
 unsafeBitCast is even cooler. How did you find out about these APIs? None of them seem to be in the docs.Darren
 @Bill I found them by poking around the Swift standard library header (Command+Click on a standard library function or symbol) . All of the interesting functions and classes have "Unsafe" in their name or comments.
  sfaxon
 I posted the updated lldb expression that got me started on Xcode 7.3 here: stackoverflow.com/questions/29441418/… 
  Martin R
 In Swift 3: 
  e let $layer = unsafeBitCast(0x7fd120f474b0, to: CALayer.self)Explore related questions
See similar questions with these tags.
default