Reactive Programming in iOS with Combine

Feb 4 2021 Swift 5.3, macOS 11.0, Xcode 12.2

Part 1: Getting Started

2. Publishers and Subscribers

Lesson Complete

Play Next Lesson
Next
Save for later
About this episode

See course reviews

See forum comments
Cinema mode Mark as Complete Download course materials
Previous episode: 1. Introduction Next episode: 3. Subscriber Operators and Subjects

This video was last updated on Feb 4 2021

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

You can unlock the rest of this video course, and our entire catalogue of books and videos, with a kodeco.com Professional subscription.

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