[ACCEPTED]-Is It Possible to NSLog C Structs (Like CGRect or CGPoint)?-cocoa-touch
You can try this:
NSLog(@"%@", NSStringFromCGPoint(cgPoint));
There are a number of functions 4 provided by UIKit that convert the various CG structs into 3 NSString
s. The reason it doesn't work is because 2 %@
signifies an object. A CGPoint
is a C struct (and 1 so are CGRect
s and CGSize
s).
There are a few functions like:
NSStringFromCGPoint
NSStringFromCGSize
NSStringFromCGRect
NSStringFromCGAffineTransform
NSStringFromUIEdgeInsets
An example:
NSLog(@"rect1: %@", NSStringFromCGRect(rect1));
0
NSLog(@"%@", CGRectCreateDictionaryRepresentation(rect));
0
I use the following macro to help me out 3 with NSRect:
#define LogRect(RECT) NSLog(@"%s: (%0.0f, %0.0f) %0.0f x %0.0f",
#RECT, RECT.origin.x, RECT.origin.y, RECT.size.width, RECT.size.height)
You could do something similar 2 for CGPoint:
@define LogCGPoint(POINT) NSLog(@"%s: (%0.0f, %0.0f)",
#POINT POINT.x, POINT.y);
Using it as follows:
LogCGPoint(cgPoint);
Would produce 1 the following:
cgPoint: (100, 200)
You can use NSValue
for this. An NSValue object is a simple 5 container for a single C or Objective-C 4 data item. It can hold any of the scalar 3 types such as int, float, and char, as well 2 as pointers, structures, and object ids.
Example:
CGPoint cgPoint = CGPointMake(10,30);
NSLog(@"%@",[NSValue valueWithCGPoint:cgPoint]);
OUTPUT : NSPoint: {10, 30}
Hope 1 it helps you.
Yes, you can use bellow few functions like: First 2 you have to convert CGPoint struct into 1 string, see example
1) NSStringFromCGPoint,
2) NSStringFromCGSize,
3) NSStringFromCGRect,
4) NSStringFromCGAffineTransform,
5) NSStringFromUIEdgeInsets,
For example:
1) NSLog(@"NSStringFromCGPoint = %@", NSStringFromCGRect(cgPointValue));
Like this...
Since Stack Overflow’s broken RSS just resurrected 2 this question for me, here’s my almost-general 1 solution: JAValueToString
This lets you write JA_DUMP(cgPoint)
and get cgPoint = {0, 0}
logged.
NSLog(@"%@",CGRectCreateDictionaryRepresentation(rect));
0
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.