Objective-C: NSLog () of C struct

o CGPoint , ad esempio. The syntax NSLog(@"%@", ... ); works and is used to obtain information about objects, but does not work on C data types such as struct CGRect or CGPoint , for example. o NSStringFromCGPoint : To take advantage of NSLog(@"%@", ... ); even on C-style structs can rely on conversion functions like NSStringFromCGRect() or NSStringFromCGPoint :

1
2
3
4
5
CGRect ) { 10 , 20 , 30 , 40 } ; CGRect mioRect = (CGRect) {10, 20, 30, 40};
CGPoint ) { 32 , 64 } ; CGPoint mioPoint = (CGPoint) {32, 64};
/ /
"Info rettangolo: %@" , NSStringFromCGRect ( mioRect ) ) ; NSLog (@ "Info rectangle:% @", NSStringFromCGRect (mioRect));
"Info point: %@" , NSStringFromCGPoint ( mioPoint ) ) ; NSLog (@ "Info point:% @", NSStringFromCGPoint (mioPoint));

Specifically, it is possible to improve this procedure writes of small useful macros like:

1
# Define NSLogRect (rect) NSLog (@ "% s (% 0.0f,% 0.0f)% 0.0f% 0.0fx", # rect, rect.origin.x, rect.origin.y, rect.size.width , rect.size.height)

Or:

1
2
3
4
# Define NSLogCGPoint (point) NSLog (@ "% s (% 0.0f,% 0.0f)", # point.x point, Point.y)

CGPoint ) { 32 , 64 } ; CGPoint mioPoint = (CGPoint) {32, 64};
; NSLogCGPoint (mioPoint);

That will give as output:

1
32 , 64 ) mioPoint: (32, 64)

There are no comments for this post

Leave a comment

XHTML TAG PERMIT: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> INSERTION CODE:
 <pre></pre> // blocco generico <code></code> // blocco generico [cc_actionscript][/cc_actionscript] // Actionscript [cc_actionscript3][/cc_actionscript3] // Actionscript 3 [cc_css][/cc_css] // CSS Style Sheet [cc_html][/cc_html] // HTML [cc_js][/cc_js] // Javascript [cc_objc][/cc_objc] // Objective-C [cc_php][/cc_objc] // PHP [cc_sql][/cc_sql] // SQL 


Stop SOPA