swift 闭包传值

1.typealias myBlockArrCityAndId = (Array<Any>,Array<Any>,String) -> Void

2.var myBlock:myBlockArrCityAndId?

3.func baoCunBtn(){

      var cityName:String = ""

      var id:String = ""

      if self.myBlock != nil{

         for i in 0..<self.arrStr.count{

            let str = self.arrStr[i]

            cityName = str + "," + cityName

            let d = self.arrStrID[i]

            id = "\(d)" + "," + id

         }

            self.myBlock!(arrStr,arrStrID,id)

      }

   }

   func myBlockAll(tempClosure:@escaping myBlockArrCityAndId){

      self.myBlock = tempClosure

   }

4.回调

vc.myBlockAll(tempClosure: { (arrCity:Array, arrID:Array, id:String) in

            self.cityName = arrCity as! [String]

            self.cityID = arrID as! [Int]

            self.strCityId = id

         })

 

posted @ 2017-04-14 10:46  尸者禾火雨相  阅读(140)  评论(0编辑  收藏  举报