1. Send a notification. (Take this notification as an example. The notification name is gameOverNotification. Notification parameter: title)
Nsicationicationcenter. defacenter Center (). postNotificationName ("gameOverNotification", object: title)
2. Add an observer to the viewDidload method to listen to the notification.
NSNotificationCenter. defacenter Center (). addObserver (self, selector: "gameOver:", name: "gameOverNotification", object: nil)
3. Implement selector in step 2 and listen to the method of notification call
Func gameOver (title: NSNotification) {var str = title. object as String self. titleLable. text = str}
Reminder: the parameter in the call method of the notification here must be NSNotification, because we send one notification.
Tip: In swift, notifications are generally used if the logical structure of the project is not clear.