我正在将Objective C
代码转换为Swift
。找到这段代码:
#define MPLog(fmt, ...) \
do { \
if ([MPPush getLoggingPref] && ![MPPush getEnvironmentPref]) { \
NSLog(fmt, ##__VA_ARGS__); \
} \
} while(0)
我知道这段代码的作用但是我无法转换它。我发现this很棒的链接,但这只有Objective C
参考。
Swift提供了一些表达式来记录行号和方法名称:
Literal Type Value
#file String The name of the file in which it appears.
#line Int The line number on which it appears.
#column Int The column number in which it begins.
#function String The name of the declaration in which it appears.
例如:
func logFunctionName(string: String = #function) {
print(string)
}
func myFunction() {
logFunctionName() // Prints "myFunction()".
}
有关更多信息,请查看official documentation