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.