swift lazy initialization

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// {#code#}() 是执行闭包函数
lazy var someView: UIView = {
var result = UIView()
//do something
return result
}()
// lazy 是延迟加载的关键字,也可以直接用
lazy var someView: UIView = UIView()
// 或者
lazy var someView: UIView = SomeViewController.setupSomeView()
static func setupSomeView() -> UIView {
// setup someView
return someView
}