views:

74

answers:

2

Hi, how can i simplify that code in one line?

CGRect screen = [[UIScreen mainScreen] bounds];
NSLog(@"%@",  screen.size.width);

Thanks for your time.

+1  A: 

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]);
Alex Reynolds
Thanks for your really fast answer. Nice to know. Have a nice day.
geforce
+1  A: 

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));
progrmr