Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is It Possible to NSLog C Structs (Like CGRect or CGPoint)?

I want to be able to debug C structures without having to explicitly type every property that they consist of.

i.e. I want to be able to do something like this:

CGPoint cgPoint = CGPointMake(0,0); NSLog(@"%@",cgPoint); 

Obviously the '%@' won't work, hence the question.

like image 888
mazniak Avatar asked Feb 15 '09 02:02

mazniak


2 Answers

You can try this:

NSLog(@"%@", NSStringFromCGPoint(cgPoint)); 

There are a number of functions provided by UIKit that convert the various CG structs into NSStrings. The reason it doesn't work is because %@ signifies an object. A CGPoint is a C struct (and so are CGRects and CGSizes).

like image 158
Alex Avatar answered Sep 18 '22 19:09

Alex


There are a few functions like:

NSStringFromCGPoint   NSStringFromCGSize   NSStringFromCGRect   NSStringFromCGAffineTransform   NSStringFromUIEdgeInsets 

An example:

NSLog(@"rect1: %@", NSStringFromCGRect(rect1)); 
like image 21
steve Avatar answered Sep 19 '22 19:09

steve