Jerry Krinock
Jerry Krinock

Reputation: 5020

Swift 3 and lldb: Print frame of UIView, given hex address

Debugging iOS target, Swift 3, Xcode 8.2, lldb-360.1.68

I want to print the frame of a UIView whose address I had grabbed at an earlier breakpoint. Here is my best shot, and the disappointing result:

(lldb) expr -l objc -O -- NSStringFromRect((CGRect)([(UIView*)0x7a241b30 frame]))
error: use of undeclared identifier 'CGRect'

Thank you!

Upvotes: 3

Views: 1551

Answers (2)

featherless
featherless

Reputation: 2141

If you're in the swift debugger you can use unsafeBitCast to cast your pointer to a type.

po unsafeBitCast(0x7a241b30, to: UIView.self).frame

Upvotes: 7

Jerry Krinock
Jerry Krinock

Reputation: 5020

I found kind of an answer – more precisely, a work-less-around. You don't need to print frame, or bounds, because their values are included in the description. In this case, just enter

(lldb) po (UIView*)0x7a241b30

The values of frame and boundswill be there amid the several hundred lines of stdout you'll get.

I would still appreciate an explanation of why CGRect is a undeclared identifier, etc.

Upvotes: 1

Related Questions