p.123: println(voiceNameForIdentifier(voice)!)


Hmmm....on p. 123, the text defines the voiceNameForIdentifier(_:) function such that it can return nil in three different ways, yet the println() statement forcibly(!) unwraps the returned optional???  And no explanation is required in the text because it's patently obvious why someone would forcibly unwrap the optional there?

The if-let construct inside the voiceNameForIdentifier(_:) function is saying to me, "We don't know if we are going to find a dictionary associated with this identifier", but the println() statement seems to be saying the opposite: "We know a dictionary will be found for this identifier, so we can forcibly unwrap the return value of the function."  

And in fact, the println() statement is also saying that not only will the dictionary associated with the identifier be found, but the value corresponding to the NSVoiceName key in the dictionary will exist AND that it will successfully cast to a String.    Yet, the code in the function uses as? to cast to a String type, which means the function is saying the opposite, "It's not certain that the value can be cast to a String type."

Hmmm…on p. 123, the text defines the voiceNameForIdentifier(_:slight_smile: function such that it can return nil in three different ways, yet the println() statement forcibly(!) unwraps the returned optional??? And no explanation is required in the text because it’s patently obvious why someone would forcibly unwrap the optional there?

The if-let construct inside the voiceNameForIdentifier(_:slight_smile: function is saying to me, “We don’t know if we are going to find a dictionary associated with this identifier”, but the println() statement seems to be saying the opposite: “We know a dictionary will be found for this identifier, so we can forcibly unwrap the return value of the function.”

And in fact, the println() statement is also saying that not only will the dictionary associated with the identifier be found, but the value corresponding to the NSVoiceName key in the dictionary will exist AND that it will successfully cast to a String. Yet, the code in the function uses as? to cast to a String type, which means the function is saying the opposite, “It’s not certain that the value can be cast to a String type.”

Hi, I didn’t see a reply to this query and am having the same issue. Not sure if this is a Swift 1.0 to Swift 2.0 problem, but a word from BNR on the subject would certainly be helpful.