func print(debug: Any = "",
function: String = #function,
file: String = #file,
line: Int = #line) {
var filename = file
if let match = filename.range(of: "[^/]*$", options: .regularExpression) {
filename = filename.substring(with: match)
}
Swift.print("Log:\(filename):L\(line):\(function) \(debug)")
}
使い方
override func viewDidLoad() {
super.viewDidLoad()
print() // Log:ViewController.swift:L27:viewDidLoad()
print(debug: "Hello.") // Log:ViewController.swift:L28:viewDidLoad() Hello.
}
ファイル名、行数、関数名が表示されて便利