It has kind of become a habit of mine to log to console at almost every method for easy bug tracking. However, using NSLog doesn't show you what method unless you do something like:
NSLog(@"MyViewController:viewDidLoad");
Which is rather cumbersome when you add logging to many methods. This is where my savior comes into the picture.
By adding the following to your "MyApp-Prefix.pch" file in the "Supporting Files"-group
// DLog is almost a drop-in replacement for NSLog
// DLog();
// DLog(@"here");
// DLog(@"value: %d", x);
// Unfortunately this doesn't work DLog(aStringVariable); you have to do this instead DLog(@"%@", aStringVariable);
#ifdef DEBUG
# define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
#else
# define DLog(...)
#endif
// ALog always displays output regardless of the DEBUG setting
#define ALog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
you can use ALog (always log) and DLog (debug log) for a rich debug logging.
Simply putting DLog(); in your viewDidAppear method will output something like:
[MainViewController viewDidAppear:] [Line 169]
The blog post where I found this information is >>here
記載されている会社名、および商品名等は、各社の商標または登録商標です。
0 コメント:
コメントを投稿