前端之家收集整理的这篇文章主要介绍了
Swift基础篇——懒加载,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
懒加载
import UIKit
class ViewController: UIViewController {
lazy var listData: [String]? = {
()->[String]
in
print("----")
return ["longshao","guangzhou",0)">"beijing",0)">"shenzhen"]
}()
lazy var listData2: [String]? = {
print("shenzhen"]
}()
lazy var listData3: [String]? = self.test()
func test() -> [String]
{
print("+++")
"lnj1",0)">"lmj1",0)">"why1",0)">"wsz1"]
}
override func touchesBegan(touches: Set<UITouch>,withEvent event: UIEvent?) {
print(listData!)
print(listData)
print(listData)
print("++++++++++++++++++++++++++++")
print(listData2)
print(listData2)
print(listData2)
print("++++++++++++++++++++++++++++")
print(listData3)
print(listData3)
print(listData3)
}
}
原文链接:https://www.f2er.com/swift/325660.html