Skip to content

Instantly share code, notes, and snippets.

@alexpaul
Created July 31, 2020 21:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexpaul/84a6270355e9d4189ae8856bd548388d to your computer and use it in GitHub Desktop.
Save alexpaul/84a6270355e9d4189ae8856bd548388d to your computer and use it in GitHub Desktop.
@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