123

作者: nbhhcty | 来源:发表于2019-02-16 17:17 被阅读1次

    以下函数会打印出什么?

    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

    相关文章

      网友评论

          本文标题:123

          本文链接:https://www.haomeiwen.com/subject/jpkmxttx.html