0Pricing
Swift Academy · Lesson

Posting and Observing Notifications

Send and receive app-wide events.

NotificationCenter

NotificationCenter is a broadcast mechanism: one part of the app posts a notification and any number of observers react, without the sender and receivers knowing each other.

The Default Center

Most code uses NotificationCenter.default, a shared center that routes notifications across the process.

import Foundation

let center = NotificationCenter.default
print("Using the default notification center")

All lessons in this course

  1. Posting and Observing Notifications
  2. Notification userInfo Payloads
  3. Removing Observers Safely
  4. The Observer Pattern Alternatives
← Back to Swift Academy