SlideShare a Scribd company logo
NotificationCenter
Jintin
How to dispatch
Information ?
Hollywood Principle
Observer Pattern
Observer Pattern
• Event Driven

• Easy to write

• Decoupling
Observer Pattern
Observer Subject
Register / Unregister
Notify
iOS NotificationCenter
iOS NotificationCenter
Observer
Notification
CenteraddObserver /

removeObserver
post notification
Subject
Call Selector
iOS NotificationCenter
• Define new Notification.Name

• Add Observer to NotificationCenter with callback
Selector by given Notification.Name

• Post event to NotificationCenter with associate
Notification.Name

• Remove Observer when stop listening
Code sample
// Define key
let key = Notification.Name("name")
// Register to receive notification
NotificationCenter.default.addObserver(self, selector:
#selector(callback), name: key, object: nil)
// Post notification
NotificationCenter.default.post(name: key, object: nil)
// Stop listening notification
NotificationCenter.default.removeObserver(self, name: key,
object: nil);
Pros & Cons
• Easy to write

• Less code

• Decouple

• ….
• Hard to debug

• Hard to maintain

• Leak

• ….
Q&A

More Related Content

PDF
아이폰강의(3)
PPTX
Observer pattern
PDF
Distributing information on iOS
PPTX
pattern v
PPT
Observer pattern
PPTX
Design Pattern - Observer Pattern
PDF
JavaScript Observer Pattern Presentation (1).pdf
아이폰강의(3)
Observer pattern
Distributing information on iOS
pattern v
Observer pattern
Design Pattern - Observer Pattern
JavaScript Observer Pattern Presentation (1).pdf

Similar to iOS NotificationCenter intro (13)

PDF
Design Patterns in iOS
PPTX
Observer pattern
PDF
iOS Remote Notifications
PPTX
RESTful Notification
PPTX
Restful Asynchronous Notification
PPTX
Observer Software Design Pattern
PPTX
Observer
PDF
KVO implementation
PPTX
Notification Framework
ODP
Design Pattern - 2. Observer
PDF
What's New in User Notifications Framework - WWDC16. Meetup @Wantedly with 日本...
PDF
Actor based approach in practice for Swift developers
PPTX
Apple.combine
Design Patterns in iOS
Observer pattern
iOS Remote Notifications
RESTful Notification
Restful Asynchronous Notification
Observer Software Design Pattern
Observer
KVO implementation
Notification Framework
Design Pattern - 2. Observer
What's New in User Notifications Framework - WWDC16. Meetup @Wantedly with 日本...
Actor based approach in practice for Swift developers
Apple.combine
Ad

More from Jintin Lin (16)

PDF
KSP intro
PDF
Annotation Processing
PDF
我的開源之旅
PDF
Dagger 2 vs koin
PDF
ButterKnife
PDF
數學系的資訊人生
PDF
Instant app Intro
PDF
App design guide
PDF
J霧霾
PDF
transai
PDF
Swimat - Swift formatter
PDF
Swift Tutorial 2
PDF
Swift Tutorial 1
PDF
Andle
PDF
Realism vs Flat design
PDF
Android Service Intro
KSP intro
Annotation Processing
我的開源之旅
Dagger 2 vs koin
ButterKnife
數學系的資訊人生
Instant app Intro
App design guide
J霧霾
transai
Swimat - Swift formatter
Swift Tutorial 2
Swift Tutorial 1
Andle
Realism vs Flat design
Android Service Intro
Ad

Recently uploaded (20)

PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Electronic commerce courselecture one. Pdf
PDF
Approach and Philosophy of On baking technology
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Encapsulation theory and applications.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Getting Started with Data Integration: FME Form 101
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
Empathic Computing: Creating Shared Understanding
PPT
Teaching material agriculture food technology
PPTX
Machine Learning_overview_presentation.pptx
PPTX
A Presentation on Artificial Intelligence
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Encapsulation_ Review paper, used for researhc scholars
Electronic commerce courselecture one. Pdf
Approach and Philosophy of On baking technology
Diabetes mellitus diagnosis method based random forest with bat algorithm
A comparative analysis of optical character recognition models for extracting...
Building Integrated photovoltaic BIPV_UPV.pdf
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
MIND Revenue Release Quarter 2 2025 Press Release
Encapsulation theory and applications.pdf
Spectral efficient network and resource selection model in 5G networks
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Digital-Transformation-Roadmap-for-Companies.pptx
Getting Started with Data Integration: FME Form 101
Network Security Unit 5.pdf for BCA BBA.
Assigned Numbers - 2025 - Bluetooth® Document
Empathic Computing: Creating Shared Understanding
Teaching material agriculture food technology
Machine Learning_overview_presentation.pptx
A Presentation on Artificial Intelligence

iOS NotificationCenter intro