我正在尝试这些代码行
class Student {
var name: String
var age: Int?
init(name: String) {
self.name = name
}
func description() -> String {
return age != nil ? "\(name) is \(age) years old." : "\(name) hides his age."
}
}
var me = Student(name: "Daniel")
println(me.description())
me.age = 18
println(me.description())
上面的代码产生如下
Daniel hides his age.
Daniel is Optional(18) years old.
我的问题是为什么那里有可选(18),我如何才能删除可选的而只是打印
Daniel is 18 years old.
扬帆大鱼
汪汪一只猫