arkilis
6/2/2017 - 11:58 PM

swift_optional1.swift

swift_optional1.swift


func getPrice(name: String) -> Float? {
    if (name == "item1") {
        return 10.0
    } else if (name == "item2") {
        return 20.0
    }
    return nil
}


var price:Float? = getPrice(name: "item")
let text = "Price is - "
let message = text + "\(price)"  // compile-time error: error: value of optional type 'String?' not unwrapped; did you mean to use '!' or '?'?
print(message)