Created
September 6, 2024 15:10
-
-
Save lucianoschillagi/6ab379e2ebd6815d5c4b01f6571bdceb to your computer and use it in GitHub Desktop.
property observers example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Cocoa | |
| /// Property Observers 👀 | |
| class Person { | |
| var favoriteColor = "BLUE" { | |
| // and now my 'favoriteColor' will be... | |
| willSet(newFavoriteColor) { | |
| print("My favorite color NOW is '\(newFavoriteColor)'") | |
| } | |
| // my 'favoriteColor' was... | |
| didSet { | |
| print("My favorite color was '\(oldValue)'") | |
| } | |
| } | |
| } | |
| let changingPerson = Person() | |
| changingPerson.favoriteColor = "RED" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment