在Swift中声明全局宏

时间:2016-05-02 09:47:15

标签: objective-c swift

我想在Objective C

上声明一个宏函数
    #define SIGNATURE_END() { if([[Config sharedInstance]    checkConsoleLevel:ConsoleLogVerbose] == YES) { NSString *message = [NSString stringWithFormat:@"<< %s",__PRETTY_FUNCTION__]; Verbose(message); } }

这段代码我想用swift写的?

1 个答案:

答案 0 :(得分:2)

您需要一种调试输出。它就像在Swift中一样完成:

func __enter(file: String = #file, line: Int = #line, column: Int = #column, function: String = #function) {
    print("\(file):\(line):\(column) >> \(function)")
}

func __leave(file: String = #file, line: Int = #line, column: Int = #column, function: String = #function) {
    print("\(file):\(line):\(column) << \(function)")
}

func xxx() {
    __enter()
    print("xxx")
    __leave()
}

xxx()

/*
/var/folders/mz/4rdq8yg95v56bhbndfvnr7z4lwl1px/T/lldb/875/playground162.swift:13:12 >> xxx()
xxx
/var/folders/mz/4rdq8yg95v56bhbndfvnr7z4lwl1px/T/lldb/875/playground162.swift:15:12 << xxx()
*/

确切的代码显然取决于您不能很好解释的具体需求。希望这会有所帮助。