'String' does not conform to expected type 'CVarArg'

It seems like you're using the Vapor framework, and i quote:

Not all of the core libs (Foundation) is available on Linux yet.

The issue you created over at Vapor has gotten an answer already: https://github.com/vapor/vapor/issues/870


NSLog takes as the first argument a format string, which is followed by a list of arguments, which are substituted for the placeholders in the format string (compare String Format Specifiers).

On Apple platforms, you can print a String using the %@ format:

let fileName = "the file"
NSLog("File not found: %@", fileName)

However, this does not work on Linux platforms (such as Vapor). Here you have to convert the Swift string to a C string in order to pass it as an argument to NSLog (and use the %s format for C strings):

let fileName = "the file"
fileName.withCString {
    NSLog("File not found: %s", $0)
}

Tags:

Swift

Vapor