标签:lazy swift懒加载lazy
// Swift懒加载使用lazy关键字来修饰属性
// 在属性后面跟= {}进行具体的赋值
// 只会被加载一次
lazy var names : [String]? = {
// () -> ([String]) in
print("加载数据")
return ["why", "lnj", "lmj"]
}()
override func viewDidLoad() {
super.viewDidLoad()
}
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
print(names);
print(names);
print(names);
print(names);
}
标签:lazy swift懒加载lazy
原文地址:http://guangguang96.blog.51cto.com/12032327/1850754