Option型
func compute(_ opt: Int?) -> String { return opt.map { "The value is: \($0)" } ?? "No value" } let full = 42 let empty: Int? = nil print("compute(full) -> \(compute(full))") print("compute(empty) -> \(compute(empty))")
compute full -> The value is: 42 compute empty -> No value