Reputation: 2643
how can i simplify that code in one line?
CGRect screen = [[UIScreen mainScreen] bounds];
NSLog(@"%@", screen.size.width);
Thanks for your time.
Upvotes: 2
Views: 6034
Reputation: 77191
I would suggest:
NSLog(@"%1.0f", [UIScreen mainScreen].bounds.size.width);
To get both height and width you can use NSStringFromCGSize:
NSLog(@"%@", NSStringFromCGSize([UIScreen mainScreen].bounds.size));
Upvotes: 2
Reputation: 96937
This statement will cause an exception, or should:
NSLog(@"%@", screen.size.width);
The width
property returns a CGFloat
. You would need to change your log statement to:
NSLog(@"%f", screen.size.width);
If you want everything on one line:
NSLog(@"%f", [[[[UIScreen mainScreen] bounds] size] width]);
Upvotes: 3