如何通过通知发送一个数字和一个字符串…
let mynumber=1;
let mytext="mytext";
NSNotificationCenter.defaultCenter().postNotificationName("refresh",object: ?????????????);
并接收接收器中的值?
func refreshList(notification: NSNotification){
let receivednumber=??????????
let receivedString=?????????
}
解决方法
您可以将它们包装在NSArray或NSDictionary或自定义对象中.
例如:
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"]
}