class ViewController: UIViewController {
//格式:定义变量时前使用lazy来修饰变量,后面通过等到赋值一个闭包
// 注意点:1.必须是用var 2.闭包后面必须跟上()
lazy var detaList:[String] = {
()->[String]
in
print("我被骗了")
return ["","",""]
}()
//如果闭包是用于懒加载,那么in之前的代码都可以删除 包括in在内
lazy var detaList2:[String] = {
print("我被骗了2")
return ["","",""]
}()
let demoFunc = {
()->[String]
in
print("我被骗了3")
return ["","",""]
}
lazy var dataList3:[String] = self.demoFunc()
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
print(detaList)
print(detaList2)
print(dataList3)
print(demoFunc())
}
}