gpt4 book ai didi

swift - NSLog 不可用

转载 作者:可可西里 更新时间:2023-11-01 00:22:37 25 4
gpt4 key购买 nike

我有以下功能:

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

这会导致以下错误:

'NSLog' has been explicitly marked unavailable here (Foundation.NSLog)

在文档中明确列为可用。我想念什么?

最佳答案

与C类似,不能直接传递可变参数列表到另一个功能。您必须创建一个 CVaListPointer(Swift相当于 va_list) 并将其传递给 NSLogv 变体:

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

(Swift 3 代码。)

关于swift - NSLog 不可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37993693/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com