NSLog with CGPoint data

Spanky picture Spanky · Sep 25, 2009 · Viewed 42.4k times · Source

I have a CGPoint called point that is being assigned a touch:

UITouch *touch = [touches anyObject];

CGPoint point = [touch locationInView:self];

I want to get the x coordinate value into my console log:

NSLog(@"x: %s", point.x);

When I use this, log output for this is:

x: (null)

I have verified that point is not null when this is called using the debugger and variable watch.

Any help appreciated,

Thanks // :)

Answer

Jens Ayton picture Jens Ayton · Sep 25, 2009

Actually, the real easiest way to log a CGPoint is:

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

The desktop Cocoa equivalent is NSStringFromPoint().