Swift准备了几个很有用的编译符号。
__FILE__:string类型,包含了这个符号的文件的路径
__FUNCTION__:String类型,包含这个符号的方法的名字
__LINE__:Int类型,符号出现的行号
__COLUMN:Int类型,符号出现的列
自定义Log输出方法:
func printLog<T>(message:T,
file: String =__FILE__,
method: String =__FUNCTION__,
line: Int =__LINE__) {
let path = fileas NSString?
#if DEBUG
print("路径:\(path!.lastPathComponent)[\(line)],方法:\(method),信息:\(message)")
#endif
}
使用:printLog("test")
输出:
路径:ViewController.swift[19],方法:viewDidLoad(),信息:test