__FILE__已弃用,将在swift 3

时间:2016-03-23 05:35:51

标签: ios swift

我有这行代码

NSLog("\(__FILE__)  \(__LINE__)  \(__COLUMN__)  \(__FUNCTION__)")

我更新到xcode 7.3,现在我收到一条警告,声明此方法已弃用,将在swift 3中删除。

我尝试将代码更改为

NSLog("\(#file)  \(#line)  \(#column)  \(#function)")

但我仍然得到同样的警告。造成这种情况的原因是什么?

1 个答案:

答案 0 :(得分:0)

打印效果很好,可能会将其打包成公共功能:

public func superLog(_ fileName: String, definition: String, lineNumber: Int, variable: String, value: Any) { let fn = fileName.replacingOccurrences(of:"/Users/userName/Documents/IOS/project/", with: "") print("\n \(fn) \(lineNumber)\n \(definition)\n\n(variable)\n➳",value,"\n") } superLog(#file, definition: "log", lineNumber: #line, variable: "var", value: value)