NSLog is unavailable

邮差的信 提交于 2020-02-14 01:37:52

问题


I have following function:

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

Wich result in the following error: 'NSLog' has been explicitly marked unavailable here (Foundation.NSLog)

Within the documentation is it explicit listed as available. What do I miss?


回答1:


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.)



来源:https://stackoverflow.com/questions/37993693/nslog-is-unavailable

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!