我们经常会输出一些坐标尺寸信息之类的,比如view的frame,是CGRect类型的,用frame.oringial.x 和frame.size.width来做NSLog参数好麻烦,还好苹果对这些常用的数据提供了字符串转换的方法,如下:
NSString *NSStringFromCGPoint( CGPoint point);NSString *NSStringFromCGSize( CGSize size);NSString *NSStringFromCGRect( CGRect rect);NSString *NSStringFromCGAffineTransform( CGAffineTransform transform);NSString *NSStringFromUIEdgeInsets( UIEdgeInsets insets);NSString *NSStringFromUIOffset( UIOffset offset);
使用方法举例:
NSLog ( @"frame: %@, bounds: %@" , NSStringFromCGRect (test View . frame), NSStringFromCGRect (test View . bounds ));
对于NSArray和NSDictionary这些容器则提供了description方法:
- ( NSString *)description;
使用方法举例:
NSMutableDictionary *dict = [[ NSMutableDictionary alloc ] init ];//add valuesNSLog ( @"log dict =%@" , [dict description ]);