Some websites recommend to initialize views using lazy initialization instead of using a storyboard.
It works when self is not used in lazy initialization.
But when self is used in it, a compile error occurs.
For example, in the following code, label1 can be compiled successfully, but label2 can't, because self is used in it.
How to use self in lazy initializations?
class A {
private let label1: UILabel = {
return UILabel()
}()
private let label2: UILabel = {
let view = UILabel()
self.addTextToLabel(view) // compile error !!!
return view
}()
private func addTextToLabel(label: UILabel) {
label.text = "test"
}
}