我們經(jīng)常會輸出一些坐標尺寸信息之類的竞慢,比如view的frame,是CGRect類型的,用frame.oringial.x 和frame.size.width來做NSLog參數(shù)好麻煩,還好蘋果對這些常用的數(shù)據(jù)提供了字符串轉(zhuǎn)換的方法,如下:
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 values
NSLog ( @"log dict =%@" , [dict description ]);