NSLog でどんな情報が表示できるか少し調べてみた。
まとめ
| シンボル | 説明 | 例 |
| __FILE__ | ファイル名 | /proj/classes/ViewController.m |
| __LINE__ | ソースコードの行番号 | 364 |
| __FUNCTION__ | メソッド名(関数名) | -[ViewController viewDidLoad:] |
| __PRETTY_FUNCTION__ | クラス名とメソッド名 | -[ViewController viewDidLoad:] |
__FILE__の例
コード
NSLog(@"__FILE__: %s", __FILE__);結果
__FILE__: /Users/hashi/Development/
IOS-Sample-Code/XcodeMacro/Classes/ViewController.m__LINE__の例
コード
NSLog(@"__LINE__: %d", __LINE__);結果
__LINE__: 44
__FUNCTION__の例
クラスメソッド内
コード+ (void)ClassFooMethodWith:(NSString*)arg1 and:(NSString*)arg2
{
NSLog(@"__FUNCTION__: %s", __FUNCTION__);
}結果__FUNCTION__: +[ViewController ClassFooMethodWith:and:]
インスタンスメソッド内
コード- (void)InstanceFooMethodWith:(NSString*)arg1 and:(NSString*)arg2
{
NSLog(@"__FUNCTION__: %s", __FUNCTION__);
}結果__FUNCTION__: -[ViewController InstanceFooMethodWith:and:]
関数内
コードvoid Function(NSString* arg1)
{
NSLog(@"__FUNCTION__: %s", __FUNCTION__);
}結果__FUNCTION__: Function
__PRETTY_FUNCTION__の例
クラスメソッド内
コード+ (void)ClassFooMethodWith:(NSString*)arg1 and:(NSString*)arg2
{
NSLog(@"__PRETTY_FUNCTION__: %s", __PRETTY_FUNCTION__);
}結果__PRETTY_FUNCTION__: +[ViewController ClassFooMethodWith:and:]
インスタンスメソッド内
コード- (void)InstanceFooMethodWith:(NSString*)arg1 and:(NSString*)arg2
{
NSLog(@"__PRETTY_FUNCTION__: %s", __PRETTY_FUNCTION__);
}結果__PRETTY_FUNCTION__: -[ViewController InstanceFooMethodWith:and:]
関数内
コードvoid Function(NSString* arg1)
{
NSLog(@"__PRETTY_FUNCTION__: %s", __PRETTY_FUNCTION__);
}結果__PRETTY_FUNCTION__: Function
参考情報
NSLog:NSLog
NSLogの日本語リファレンス。書式が詳しく解説されていて役立つ。
NSLog tips and tricks - Stack Overflow
NSLogの様々な Tips。面白い。



Responses
Leave a Response