这里我写的是个传值的例子,介绍通知,跟OC的使用基本差不多
@H_403_3@let center = NSNotificationCenter.defaultCenter() center.addObserver(self,selector: "getValue:",name: "name",object: nil) @H_403_3@func getValue(object: NSNotification) ->Void{ print(object.object) print("object") } @H_403_3@func click()->Void{ let dic = NSMutableDictionary() dic.setValue("str",forKey: "name") print(dic) NSNotificationCenter.defaultCenter().postNotificationName("name",object: dic as [NSObject: AnyObject]) self.dismissViewControllerAnimated(true) { () -> Void in // } }使用之后记得移除
@H_403_3@deinit{ // 移除通知 // NSNotificationCenter.defaultCenter().removeObserver(self,object: nil) // NSNotificationCenter.defaultCenter().removeObserver(self) }Swift / OC 进阶群: 498143780