'String' does not match expected type 'CVarArg'

When I try to log in using NSLog, I encounter this error:

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

Here is my code:

if fileManager.fileExists(atPath: (drop.config["servers", "default", "KeyURL"]?.string ?? "default")) {
    NSLog("FILE AVAILABLE", "TESTNOTI")
} else {
    NSLog("FILE NOT AVAILABLE", "TESTNOTI")
}

Why is this happening and how can I fix it?

+9
source share
2 answers

NSLogtakes a format string as the first argument, followed by a list of arguments that replace the placeholders in the format string (compare String Format Specifiers ).

On Apple platforms, you can print Stringusing the format %@:

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", $0)
}
+15

, Vapor, :

(Foundation) Linux.

, Vapor, : https://github.com/vapor/vapor/issues/870

+1

Source: https://habr.com/ru/post/1671800/


All Articles