Created
July 31, 2020 21:57
-
-
Save alexpaul/84a6270355e9d4189ae8856bd548388d to your computer and use it in GitHub Desktop.
@published Property Wrapper.
This file contains 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 Combine | |
class Event { | |
@Published var calendarYear = 2020 // initial value | |
} | |
let event = Event() // new instance of Event | |
event.$calendarYear | |
.sink { newCalendar in | |
print("year is \(newCalendar)") | |
} | |
// Here the value of calendarYear is changed | |
// At this change the print statement will execute | |
event.calendarYear = 2021 | |
/* | |
year is 2020 | |
year is 2021 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment