Translate

顯示具有 NSLog 標籤的文章。 顯示所有文章
顯示具有 NSLog 標籤的文章。 顯示所有文章

2015年7月23日 星期四

How to print out the method name and line number and conditionally disable NSLog?

參考文章
#ifdef DEBUG # define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__); #else # define DLog(...) #endif #define ALog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__); #ifdef DEBUG # define ULog(fmt, ...) { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:@"%s\n [Line %d] ", __PRETTY_FUNCTION__, __LINE__] message:[NSString stringWithFormat:fmt, ##__VA_ARGS__] delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil]; [alert show]; } #else # define ULog(...) #endif

2015年6月11日 星期四

NSLog NSData Length to bytes

NSLog(@"File size is : %.2f MB",(CGFloat)myData.length/1024.0f/1024.0f);

Or for OS X 10.8+ and iOS 6+

NSLog(@"%@",[NSByteCountFormatter stringFromByteCount:myData.length countStyle:NSByteCountFormatterCountStyleFile]);

2013年6月10日 星期一

如何用NSLog输出NSRange,CGRect等结构体

參考link

使用对应的转换
NSStringFromCGPoint
NSStringFromCGSize
NSStringFromCGRect
NSStringFromCGAffineTransform
NSStringFromUIEdgeInsets
比如

NSLog(@"rect1: %@", NSStringFromCGRect(rect1));