Victim Pool interpolation error


#1

I have my code typed exactly as the book has it in the whole chapter. But my last line of
print(“Victim pool: (fredTheZombie.victimPool); population: (fredTheZombie.town?. population)”)
receives an error that says:
String interpolation produces a debug description for an optional value; did you mean to make this explicit?
Why is this happening and how do I fix it?


#2

That’s not an error; that’s just a friendly warning.

You are trying to print an optional value as in the following example.

var jibber : String? = "Hello Jabber"

// print an optional to produce a warning
print ("jibber: \(jibber)")

// unwrap the optional and print it to eliminate the warning
if let jibber = jibber {
    print ("jibber: \(jibber)")
}

Apple’s The Swift Programming Language book is a good resource worth reading.