NSLog is unavailable

后端 未结 1 675
故里飘歌
故里飘歌 2021-01-07 04:20

I have following function:

func myNSLog(_ givenFormat: String, _ args: CVarArg..., _ function:String = #function) {
        let format = \"\\(function): \\(g         


        
相关标签:
1条回答
  • 2021-01-07 05:17

    Similar as in C, you cannot pass a variable argument list directly to another function. You have to create a CVaListPointer (the Swift equivalent of va_list) and pass that to the NSLogv variant:

    func myNSLog(_ givenFormat: String, _ args: CVarArg..., _ function:String = #function) {
        let format = "\(function): \(givenFormat)"
        withVaList(args) { NSLogv(format, $0) }
    }
    

    (Swift 3 code.)

    0 讨论(0)
提交回复
热议问题