swift 广播

步骤
注册广播

      let name1 = NSNotification.Name(rawValue:"NotFicationName")
            NotificationCenter.default.addObserver(self, selector: #selector(ViewController.notfifica(sender:)), name: name1, object: nil)

注册解析广播的方法

 @objc func notfifica(sender:NSNotification) {
        print("接收广播成功")
        let dic = sender.userInfo
        let va = dic?["key"]
        print("\(va)")
        
    }

发送广播

     let noT = NSNotification.Name(rawValue: "NotFicationName")
            let dic = ["key":"value"]
            NotificationCenter.default.post(name: noT, object: nil, userInfo:dic)

你可能感兴趣的:(swift 广播)