1.发通知。(以这条通知为例,通知名字:gameOverNotification。通知参数:title)
NSNotificationCenter.defaultCenter().postNotificationName("gameOverNotification", object: title)
NSNotificationCenter.defaultCenter().addObserver(self, selector: "gameOver:", name: "gameOverNotification", object: nil)
func gameOver(title:NSNotification) { var str = title.object as String self.titleLable.text = str }
友情提示:在swift中,如果对项目的逻辑结构不是很清楚一般用通知。
原文:http://blog.csdn.net/yinqiangqiang/article/details/36177203