Hey Erica, why doesn’t this work? #swiftlang

wyu writes: “Why can I pass in an array explicitly to this code but if the array is a variable it fails?”

The String format initializer takes CVarArgType arguments, as you see in the following init declaration:

init(format: String, arguments: [CVarArgType])

Because Swift infers the assignment to args as [String], you cannot pass the array to the constructor. To fix, add explicit typing:.

let args : [CVarArgType] = ["IRC", "wyu"]
print(String(format:question, arguments: args))

Hope this helps!

Comments are closed.