how to pass multiple values with a notification in swift

前端 未结 6 1790
广开言路
广开言路 2020-11-27 05:06

How to send a number and a String through a notification ...

let mynumber=1;
let mytext=\"mytext\";
NSNotificationCenter.defaultCenter().postNotificationName         


        
6条回答
  •  半阙折子戏
    2020-11-27 05:11

    Actually there are a lot of way to do this. One of them is to pass an array of objects like :

    let arrayObject : [AnyObject] = [mynumber,mytext]
    
    NSNotificationCenter.defaultCenter().postNotificationName("refresh", object: arrayObject)
    
    func refreshList(notification: NSNotification){
    
        let arrayObject =  notification.object as! [AnyObject]
    
        let receivednumber = arrayObject[0] as! Int
        let receivedString = arrayObject[1] as! String
    }
    

提交回复
热议问题