- ファイル名
- メソッド名
- 現在行数
ファイル名
この特殊変数を使ったファイルの名前を出力します。 ファイル名だけではなく、絶対パスが返されます。メソッド名
この特殊変数を使ったメソッドの名前を出力します。現在行数
この特殊変数を使った位置が何行目かを出力します。 サンプルコードimport UIKit class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. print("------viewDidLoad start------") print("ファイル名:", #file) print("メソッド名:", #function) print("行数:", #line) print("------viewDidLoad end------") self.methodA() } func methodA() { print("------methodA start------") print("ファイル名:", #file) print("メソッド名:", #function) print("行数:", #line) print("------methodA end------") } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } }出力結果
------viewDidLoad start------
ファイル名: /Users/[user_name]/Desktop/develop/iOSApp/LogOutput/LogOutput/ViewController.swift
メソッド名: viewDidLoad()
行数: 12
------viewDidLoad end------
------methodA start------
ファイル名: /Users/[user_name]/Desktop/develop/iOSApp/LogOutput/LogOutput/ViewController.swift
メソッド名: methodA()
行数: 21
------methodA end------
これはデバッグ用に使えると思う。
どのメソッドのどの部分を通ったとかをログに出力しておくとか。
いや、もしかしたらこのようなことを書く時代ではないのかな?(^^;