willSet/didSet vs. get/set
Last updated
Was this helpful?
Last updated
Was this helpful?
⟩ ⟩ ⟩ willSet/didSet vs. get/set
willSet/didSet () vs. get/set ()
需主動調整或限制屬性值時,用 get/set。
只需監控屬性變化或執行副作用,用 willSet/didSet。
本質上不直接儲存值,不支援 willSet/didSet。
willSet/didSet 只能用於 stored property。