λ°μν
π λͺ©λ‘
- μ΅μ λ 체μ΄λ μ΄λ?
- Example
π μ΅μ λ 체μ΄λ μ΄λ?
μ΅μ λμ μν΄ μλ nil μΌμ§λ λͺ¨λ₯΄λ νλ‘νΌν°, λ©μλ, μλΈμ€ν¬λ¦½μ λ±μ κ°μ Έμ€κ±°λ νΈμΆν λ μ¬μ©ν μ μλ μΌλ ¨μ κ³Όμ
π Example
struct Developer {
let name: String
}
struct Company {
let name: String
var developer: Developer?
}
var developer = Developer(name: "Sam")
var company = Company(name: "Eddie", developer: developer)
print(company.developer)
// company.developer.name -> Error!
print(company.developer?.name) // Optional("Sam")
print(company.developer!.name) // Sam
λ°μν
'Swift' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
Swift closure (0) | 2021.11.28 |
---|---|
Swift try-catch (0) | 2021.11.28 |
Swift μ΄κ±°ν (0) | 2021.11.28 |
Swift μ΅μ€ν μ (0) | 2021.11.28 |
Swift νλ‘ν μ½ (0) | 2021.11.28 |