翻了好多的资料发现了一种比较方便的打印日志的方式:
public func print(_ items: String..., filename: String = #file, function : String = #function, line: Int = #line, separator: String = " ", terminator: String = "\n") {
#if DEBUG
let pretty = "===### \(URL(fileURLWithPath: filename).lastPathComponent) [#\(line)] \(function) ###=== \n"
let output = items.map { "\($0)" }.joined(separator: separator)
Swift.print(pretty+output, terminator: terminator)
#endif
}
感觉比较完美,顺便也学习了一下swift的 Literal Expression