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