小编典典

如何在通知中快速传递多个值

swift

如何通过通知发送数字和字符串…

let mynumber=1;
let mytext="mytext";
NSNotificationCenter.defaultCenter().postNotificationName("refresh", object: ?????????????);

并在接收器中接收值?

func refreshList(notification: NSNotification){
        let receivednumber=??????????
        let receivedString=?????????
    }

阅读 291

收藏
2020-07-07

共1个答案

小编典典

您可以将它们包装在NSArrayNSDictionary或自定义对象中。

例如:

let mynumber=1;
let mytext="mytext";

let myDict = [ "number": mynumber, "text":mytext]

NSNotificationCenter.defaultCenter().postNotificationName("refresh", object:myDict);

func refreshList(notification: NSNotification){
    let dict = notification.object as! NSDictionary
    let receivednumber = dict["number"]
    let receivedString = dict["mytext"]
}
2020-07-07