标签:orm 启动 code names copyright lazy res for over
// // ViewController.swift // 懒加载 // // Created by nanakon on 17/3/11. // Copyright © 2017年 nanakon. All rights reserved. // import UIKit class ViewController: UIViewController { // 懒加载 用到时才加载 多次使用只加载一次 // 程序一启动就创建了这个数组占据内存空间 // var names : [String] = ["why", "lmj"] //lazy var names : [String] = ["why", "lmj"] lazy var names : [String] = { let names = ["why", "lmj"] print("用到names时加载names") return names }() //lazy var btn : UIButton = UIButton() lazy var btn : UIButton = { let btn = UIButton() btn.setTitle("按钮", for: .normal) return btn }() override func viewDidLoad() { super.viewDidLoad() } override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { print(names) print(btn) } }
标签:orm 启动 code names copyright lazy res for over
原文地址:http://www.cnblogs.com/jzm17173/p/6534935.html