remote: /tmp/build_f459d376d1bc10ac2e93e52575ac5ea9/Sources/App/main.swift:368:49: error: argument type 'String' does not conform to expected type 'CVararg'remote: NSLog("file NOT AVAILABLE","TESTNOTI")remote: ^~~~~~~~~~remote: as! CVararg
mycode的
if fileManager.fileExists(atPath: (drop.config["servers","default","KeyURL"]?.string ?? "default")) { NSLog("file AVAILABLE","TESTNOTI") } else { NSLog("file NOT AVAILABLE","TESTNOTI") }解决方法 NSLog将格式字符串作为第一个参数,后面跟随
通过参数列表替换占位符
格式字符串(比较 String Format Specifiers).
在Apple平台上,您可以使用%@格式打印字符串:
let filename = "the file"NSLog("file not found: %@",filename)
但是,这在linux平台(例如Vapor)上不起作用.
在这里你必须将Swift字符串转换为C字符串才能通过
它作为NSLog的参数(并使用%s格式的C字符串):
let filename = "the file"filename.withCString { NSLog("file not found: %s",)}总结
以上是内存溢出为你收集整理的swift – ‘String’不符合预期类型’CVarArg’全部内容,希望文章能够帮你解决swift – ‘String’不符合预期类型’CVarArg’所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)