swift block

来源:互联网 发布:hd平板软件市场 编辑:程序博客网 时间:2024/05/21 09:29
B class中:
1. 然后typedef一下这个funcation:

typealias callbackfunc=(selectIndex:Int)->Void

2.var myFunc = callbackfunc?()

3.传递函数    func initBack( mathFunction:(selectIndex:Int)->Void ){
        myFunc = mathFunction
    }

4.最后回调:
myFunc!(selectIndex: indexPath.row);

A class中写法:
  xxx.initBack { (selectIndex) -> Void in
做点啥吧.
        }