打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
nslog 宏定义输出 IOS

自己改写了网络上面的nslog宏定义功能,感觉很好用,推荐给大家:

首先,在-Prefix.pch文件中加入如下代码:

  1. #ifdef DEBUG  
  2. #  define mLOG(fmt, ...) do {                                            \  
  3.         NSString* file = [[NSString alloc] initWithFormat:@"%s", __FILE__]; \  
  4.         NSLog((@"< FILE:%@; LINE:%d; FUNC:%s > --: " fmt), [file lastPathComponent], __LINE__, __func__, ##__VA_ARGS__); \  
  5.     } while(0)  
  6. #else  
  7. #  define mLOG(...)  
  8. #endif  

如果你没有使用ARC,则为下面代码:

  1. #ifdef DEBUG  
  2. #  define mLOG(fmt, ...) do {                                            \  
  3.         NSString* file = [[NSString alloc] initWithFormat:@"%s", __FILE__]; \  
  4.         NSLog((@"< FILE:%@; LINE:%d; FUNC:%s > --: " fmt), [file lastPathComponent], __LINE__, __func__, ##__VA_ARGS__); \  
  5.         [file release]; \  
  6.     } while(0)  
  7. #else  
  8. #  define mLOG(...)  
  9. #endif  

编译一下,就可以在项目任何位置使用mLOG这个代码了如下:

  1.     NSArray *arrtest = [[NSArray alloc] initWithObjects:@"one", @"tow", @"three", @"four", nil nil];  
  2.     mLOG(@"%@", arrtest);  
  3. }  
  4.   
  5. - (void)viewWillAppear:(BOOL)animated {  
  6.     [super viewWillAppear:animated];  
  7.     mLOG(@"We all good friends.");  

输出如下:

  1. 2014-05-15 12:20:14.063 ATMChaoRenJieKe1971[15222:60b] < FILE:NewsViewController.m; LINE:88; FUNC:-[NewsViewController viewDidLoad] > --: (  
  2.     one,  
  3.     tow,  
  4.     three,  
  5.     four  
  6. )  
  7. 2014-05-15 12:20:14.067 ATMChaoRenJieKe1971[15222:60b] < FILE:NewsViewController.m; LINE:93; FUNC:-[NewsViewController viewWillAppear:] > --: We all good friends.  

可以看出,方便使用还简洁,

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
深入理解Objective-C中的对象
Objective-c的@property 详解
我理解的iOS中的RunTime机制(1)
聊聊 KVC 和KVO 的高阶应用
NSObject中methodSignatureForSelector、forwardInvocation两个消息方法
NSURLConnection的使用
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服