Tuesday, May 12, 2015

Adding Notifications in Swift

Post Notification:

NSNotificationCenter.defaultCenter().postNotificationName("NotificationIdentifier", object: nil)

Add Observer for Notification in ViewWillAppear:

          
NSNotificationCenter.defaultCenter().addObserver(self, selector: "methodOfReceivedNotification:", name:"NotificationIdentifier", object: nil)


Remove in ViewWillDisappear:
        
NSNotificationCenter.defaultCenter().removeObserver(self, name: "NotificationIdentifier", object: nil)Remove in ViewWillDisappear:
Selector Method:

func methodOfReceivedNotification(notification: NSNotification){
    //Action on Notification
}

No comments:

Post a Comment