Reputation: 27335
When the debugger is stopped at a breakpoint, I can't find the frame of any of my UIViews in there.
Is it possible to do this?
EDIT: starting a bounty due to the lack of response. Just to be clear, what I am looking for is a way to see the frame without adding in extra debugging code.
Also, if the answer is "no you can't do it", bounty will go to the best explanation of why you can see some class members but not others.
Upvotes: 33
Views: 22474
Reputation: 5772
I prefer the short form for print i.e. 'p' to print the frame in lldb. For e.g.
p (CGRect)[view frame]
Upvotes: 1
Reputation: 1144
In XCode 5.1.1, you can hover over a variable that is a UIView and you will see the following type of popover:
If you click on the 'i' button, the following type of output will be printed in the debugger's console:
<UIImageView: 0xa49ca90; frame = (0 0; 640 360); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0xa46c1c0>>
This is another way of inspecting the frame of a UIView.
Upvotes: 4
Reputation: 3287
In Xcode, go to the console and type:
po viewName
If execution is inside code for the view, you can just:
po self
This will output some view details, like this:
<UIView: 0x9cca0f0; frame = (0 0; 320 480); layer = <CALayer: 0x9ccabe0>>
Upvotes: 2
Reputation: 3166
Interestingly, using the getter method to return the view's frame works:
print (CGRect)[view frame]
This gives the expected result:
(CGRect) $2 = origin=(x=0, y=20) size=(width=320, height=48)
But if you try to use dot notation, which I hear so often referred to as being provided simply for 'syntactic sugar':
print (CGRect)view.frame
You get the following error:
error: C-style cast from '<unknown type>' to 'CGRect' is not allowed
Upvotes: 3
Reputation: 21
To get a the frame information similar to the debugger as an NSString, use NSStringFromCGRect(someView.frame)
Upvotes: 0
Reputation: 1719
po [[[[UIApplication sharedApplication]windows] objectAtIndex:0] recursiveDescription]
will print out the entire view heirachy but only seems to work in gdb and not llvm
Upvotes: 3
Reputation: 1183
Found an answer for lldb. For example, this works
(lldb) print (CGRect)[((UIView *)[[[self backIV] subviews] objectAtIndex:1]) frame]
Upvotes: 1
Reputation: 33146
Re-formatting @EPage_Ed's answer because the original was hard-coded for his specific case:
At the (lldb) prompt, type:
print (CGRect)[view frame]
Or, for the bounds:
print (CGRect)[view bounds]
Upvotes: 19
Reputation: 37781
If you go to the debugger panel, you can type this in while you are at a breakpoint:
(gdb) print (CGRect) [self frame]
$1 = {
origin = {
x = 0,
y = 0
},
size = {
width = 100,
height = 100
}
}
When using the console debugger you can press the up arrow key to cycle through previous commands. Pressing return without entering a command repeats the last command.
Upvotes: 32
Reputation: 6095
Yes, you can do it. While debugging, find the UIView of interest in the variable inspector. Control-click on it and select "Print Description to Console". For example, I did this on the _view ivar of a UIViewController and the following appeared in the console:
Printing description of _view:
<UIView: 0x25b460; frame = (0 0; 320 480); autoresize = W+H; layer = <CALayer: 0x26b740>>
Upvotes: 46
Reputation: 40243
Sometimes they are just out of scope by the time you get there.
Print them to the console:
NSLog('Frame: %d, %d, %d, %d', frame.origin.x, frame.origin.y, frame.size.width, frame.size.height);
Upvotes: 0