Swift_Block

来源:互联网 发布:淘宝卖家好评不返现 编辑:程序博客网 时间:2024/06/05 02:57

//1无回调参数typealias funcBlock1 = ()->()//2有回调参数typealias funcBlock2 = (_ a:Int,_ b:Int)->()//3typealias funcBlock3 = (Int,Int) -> (String) -> ()//4typealias funcBlock4 = (Int,Int) -> (String) -> Stringvar f2:funcBlock2?class ViewController: UIViewController {    override func viewDidLoad() {        super.viewDidLoad()        // Do any additional setup after loading the view, typically from a nib.                //1        testBlock1 {            print("testBlock1 返回了")        }                        //2        testBlock2 { (a:Int, b:Int) in                        print("a=\(a) \nb=\(b)")        }                        endUseBlock2()                        inBlock(name: "MeiMei") { (newNmae:String, type:Int) in                        print("newNmae=\(newNmae) type=\(type)")        }            }       func testBlock1(b:funcBlock1) {                print("进入了testBlock1")        b()    }            func testBlock2(b:@escaping funcBlock2) {                f2 = b            }        func endUseBlock2(){                f2!(100,9999)    }        func inBlock(name:String , block:(_ newName:String,_ type:Int)->()){                block("PiaoLiangDe"+name,1)    }}


原创粉丝点击