Check Mobile App
Read now
Start a Project

Introduction of Notification Center In Swift

Save

Notification Center use for broadcasting singles or notifying the methods at the same time. It uses the Observer pattern to inform registered observers when a notification comes in, using a central dispatcher called NotificationCenter.

Before we get started, some quick notes:

Write Notification Center for Observation : –

Let’s create a project to pass and receive data one controller to second controller from Notification Center.

First ViewController:

  1. Take a label, button and a image view in a first Viewcontroller.
Firstviewcontoller

 

2.  In first controllerView , we add or remove Observer in:

         

 

            This is the notification registration process for receiving. Based on the key NotificationCenter can observe.

            The addObserver(_:selector:name:object:) function has 5 parameters:

3.  Now write functions you want to call when a notification is observed.

             

 

function has one parameter, which is a Notification object. you can use userInfo to send some data with the notification.

4.  Every notification has a name of type Notification.Name.

Second ViewController:

  1. Take two buttons in second ViewController.
second ViewController

2.   Now, add Notification Post in both button action.


 

This will call the notification method from any place and changed the label and image view according to key. It will identify based on key the observer. You can also pass data with this post Notification.

 

For other blogs Please click here

  

   

 

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

css.php

The support is fast and do everything in their power to make it perfect. If you need customization it's also done right away. I had massive research to select Mobikul and now I'm sure it was the right one.

Igor Souza

Igor Souza

Talk to Sales

Global

Live Chat
Start a Project

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home