Reactive Programming in iOS with Combine

Feb 4 2021 · Swift 5.3, macOS 11.0, Xcode 12.2

Part 1: Getting Started

02. Publishers and Subscribers

Episode complete

Play next episode

Next
About this episode

Leave a rating/review

See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 01. Introduction Next episode: 03. Subscriber Operators and Subjects

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Heads up... You've reached locked video content where the transcript will be shown as obfuscated text.

Now that you’ve learned some of the basic concepts of Combine, it’s time to jump in and learn about two of Combine’s core components: publishers and subscribers.

example(of: "NotificationCenter") {
  let center = NotificationCenter.default
  let myNotification = Notification.Name("MyNotification")

  let publisher = center
    .publisher(for: myNotification, object: nil)
}
let subscription = publisher
  .sink { _ in
    print("Notification received from a publisher!")
  }

center.post(name: myNotification, object: nil)
subscription.cancel()
——— Example of: Publisher ———
Notification received from a publisher!
.print()
——— Example of: NotificationCenter ———
receive subscription: (NotificationCenter Observer)
request unlimited
receive value: (name = MyNotification, object = nil, userInfo = nil)
Notification received from a publisher!
receive cancel