varcar ="Benz"
let closure = {
print("I drive \(car)")
}
car ="Tesla"
closure()
不同情况输出结果不一样
classRunloopVc:UIViewController{
overridefuncviewDidLoad(){
super.viewDidLoad()
varcar ="Benz"
letclosure = { [car]in
print("I drive\(car)")
}
car ="Tesla"
closure()
}
}
输出结果1:I drive Benz
如果:
```classRunloopVc:UIViewController{
overridefuncviewDidLoad(){
super.viewDidLoad()
car ="Tesla"
closure()
}
}```
varcar ="Benz"
letclosure = { [car]in
print("I drive\(car)")
}
输出结果2:I drive Tesla
网友评论