ViewController.swift
import UIKit class ViewController: UIViewController { //swift中 懒加载有非常特殊的写法 //实际上懒加载是 闭包 lazy var nameLabel: UILabel = { print("我懒了么") let l = UILabel() l.textAlignment = NSTextAlignment.Center return l }() lazy var titleLabel: UILabel = UILabel() override func viewDidLoad() { super.viewDidLoad() // print(nameLabel) // print(nameLabel) // print(nameLabel) } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } }