Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
@published Property Wrapper.
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