我看所有的教程迅速從蘋果,但我在使用的一個例子問題:選配在迅速
class Person {
var residence: Residence?
}
class Residence {
var address: Address?
}
class Address {
var buildingNumber: String? = "234"
var streetName: String? = "Main St."
var appartmentNumber: String?
}
let paul = Person()
var addressNumber: Int?
addressNumber = paul.residence?.address?.buildingNumber?.toInt()
if let number = addressNumber {
"correct"
} else {
"fault"
}
它總是打印出「故障」。我錯過了一些顯而易見的東西嗎?
'if let number = addressNumber'是什麼?這是一項任務嗎? 「故障」是否表明分配失敗? –
是的,首先,'住所'從來沒有被分配到價值 – Alladinian