import UIKitclass ViewController: UIViewController {
//懒加载在程序运行的时候不会被使用
//创建懒加载 定义是使用lazy后 面通过等号赋值一个闭包
//1.使用var 2.闭包后面必须跟上()
lazy var dataList:[String] = {
()->[String] in
print("我被点击了")
return ["ln","ln","a","asf"]
}()
//定义闭包
let demonFunc = { ()->[String] in return ["123","123"] } //懒加载的写法 lazy var datalist3:[String] = self.demonFunc() override func touchesBegan(touches: Set, withEvent event: UIEvent?) {
print(dataList)
print(dataList)
print(dataList)
print(demonFunc)
print(demonFunc())
print(datalist3)
}
}
打印结果:
网友评论