37

I'm debugging my code and trying to figure out the size of the view using this:

p view.frame.size.height

but I'm getting this error:

error: property 'frame' not found on object of type 'UIView *' error: 1 errors parsing expression

any of you knows why or how can I debug the size of my view?

HelenaM
  • 1,807
  • 6
  • 30
  • 41
  • I think you cannot use dot notation like that in the console, can you try this, i think it's going to work : `[[[[self view] frame] size] height]` – limon Jun 04 '13 at 19:57
  • I think you can use NSLog instead -- NSLog(@"Frame Height: %f", view.frame.size.height); – John Jun 04 '13 at 20:01

7 Answers7

89

If you hate typecasting every time, you can try this:

(lldb) expr @import UIKit
(lldb) po self.view.bounds

Since Xcode 7.2 is now available, I think we should update the answer.
I find the answer here, Why can't LLDB print view.bounds?

pkamb
  • 33,281
  • 23
  • 160
  • 191
Chris Yim
  • 1,392
  • 11
  • 12
53

Try this

p (CGRect)[view frame]

Alternative to get the frame of the view:

po view
Sonny Saluja
  • 7,193
  • 2
  • 25
  • 39
  • 1
    I get this error: error: Execution was interrupted, reason: EXC_BAD_ACCESS (code=2, address=0x65). The process has been returned to the state before execution. – HelenaM Jun 04 '13 at 19:51
  • I got the EXC_BAD_ACCESS because I was calling frame on the wrong object. Instead of: p (CGRect)[myviewcontroller frame] should be p (CGRect)[[myviewcontroller view] frame] – Avner Mar 29 '17 at 02:31
6

Try this,

po view.layer.frame.size.height
Harshil
  • 161
  • 2
  • 6
  • 1
    This worked for me, thank you. Makes me think that `view.frame` is simply be a shortcut for `view.layer.frame` that LLDB doesn't have access to... – Trev14 Jan 22 '19 at 22:58
3

it should have outer bracket in the first answer,like this:

p ((CGRect)[cell frame])

output:

(CGRect) $5 = origin=(x=0, y=0) size=(width=320, height=44)
inix
  • 485
  • 1
  • 5
  • 12
1

Add a pch file , add these lines of code to the file:

#ifndef PrefixHeader_pch
#define PrefixHeader_pch

#ifdef __OBJC__
#import <UIKit/UIKit.h>
#endif  

#endif /* PrefixHeader_pch */    

Next, link the pch file to your project:

enter image description here

Run the app again, then you should be able to use the dot notation in lldb console:

(lldb) po self.view.bounds    

For how to add a pch file , see the answer here PCH File in Xcode 6

Community
  • 1
  • 1
wj2061
  • 6,778
  • 3
  • 36
  • 62
0

It seems that we cannot use dot notation in the console, try to use get method.

xindong
  • 91
  • 1
  • 1
  • this worked in my case, trying to get [self traitCollection]; Dot notation failed with error, "property 'traitCollection' not found on object of type 'UIView *'", but using [self traitCollection] worked! – iOS4Life Sep 29 '20 at 18:42
-2

I had same problem and i solved it. Your class might be inherited from "UIViewController". It must be inherited from "UIView" so as to make an frame object in it.

Gurjas
  • 21
  • 1
  • 8