//1无回调参数
typealias funcBlock1 = ()->()
//2有回调参数
typealias funcBlock2 = (_ a:Int,_ b:Int)->()
//3
typealias funcBlock3 = (Int,Int) -> (String) -> ()
//4
typealias funcBlock4 = (Int,Int) -> (String) -> String
var 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)
}
}
Swift_Block
最新推荐文章于 2022-07-20 19:28:25 发布