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