Lazy Stored Properties

lazy stored property is a property whose initial value is not calculated until the first time it is used. You indicate a lazy stored property by writing the lazy modifier before its declaration.

let kScreenWidth = UIScreen.mainScreen().bounds.size.width let kScreenHeight = UIScreen.mainScreen().bounds.size.heightclassViewController: UIViewController{ lazy var wkWebView: WKWebView= { () -> WKWebViewinlet tempWebView = WKWebView() tempWebView.navigationDelegate = selfreturntempWebView }() override func viewDidLoad() {super.viewDidLoad() let someURL = ... let request: NSURLRequest= NSURLRequest(URL: someURL)self.wkWebView.loadRequest(request)self.wkWebView.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight)self.view.addSubview(self.wkWebView) } }

作者:foolishlionel
链接:https://www.jianshu.com/p/af0702a91e92
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

swift语言点评十三-Lazy的更多相关文章

  1. swift语言点评四-Closure

    总结:整个Closure的作用在于简化语言表述形式. 一.闭包的简化 Closure expression syntax has the following general form: { () -& ...

  2. swift语言点评二

    一.数据类型 1.基础类型的封装 Swift provides its own versions of all fundamental C and Objective-C types, includi ...

  3. swift语言点评十九-类型转化与检查

    1.oc比较: -(BOOL) isKindOfClass: classObj判断是否是这个类或者这个类的子类的实例 -(BOOL) isMemberOfClass: classObj 判断是否是这个 ...

  4. swift语言点评十八-异常与错误

    1.错误类型与枚举的结合 enum VendingMachineError: Error { case invalidSelection case insufficientFunds(coinsNee ...

  5. swift语言点评十七-Designated Initializers and Convenience Initializers

    Swift defines two kinds of initializers for class types to help ensure all stored properties receive ...

  6. swift语言点评十四-继承

    Overriding A subclass can provide its own custom implementation of an instance method, type method, ...

  7. swift语言点评十-Value and Reference Types

    结论:value是拷贝,Reference是引用 Value and Reference Types Types in Swift fall into one of two categories: f ...

  8. swift语言点评八-枚举

    总结:swift中的枚举可以看作变量可以作为case匹配参数的类 Enumerations 枚举的作用:状态列举与匹配 枚举值与类型 If a value (known as a “raw” valu ...

  9. swift语言点评五-Function

    一.函数类型 Every function in Swift has a type, consisting of the function’s parameter types and return t ...

随机推荐

  1. c#初学12-12-为什么mian函数必须是static的

    c#初学12-12-为什么mian函数必须是static的 c#程序刚开始启动的时候都会有唯一一个入口函数main()函数, 而非静态成员又称实例成员,必须作用于实例.在程序刚开始运行的时候,未建立任 ...

  2. 【摘录】JAVA内存管理-评估垃圾收集性能的工具

    第七章 评估垃圾收集性能的工具 各种各样的诊断和监视工具可以用来评估垃圾收集性能.本章简要概述他们中的几个.可以通过第九章中的“Tools and Troubleshooting”链接获得更多的信息. ...

  3. GCC中的强符号和弱符号及强引用和弱引用

    1. 强符号和弱符号 1.1 u-boot和kernel中的__weak指令 u-boot和kernel比较普遍地使用了__weak来定义函数. 在include\linux\compiler-gcc ...

  4. Kattis - mixedfractions

    Mixed Fractions You are part of a team developing software to help students learn basic mathematics. ...

  5. mysql定时清理binlog

    一.没有主从同步的情况下清理日志 mysql -uroot -p123456 -e 'PURGE MASTER LOGS BEFORE DATE_SUB( NOW( ),INTERVAL 5 DAY) ...

  6. 21_HTML&CSS

    今日内容: 1. HTML标签:表单标签​2. CSS: HTML标签:表单标签 * 表单: * 概念:用于采集用户输入的数据的.用于和服务器进行交互. * form:用于定义表单的.可以定义一个范围 ...

  7. 一些特殊ACII码的用法 在控制台中覆盖显示、刷新显示和删除字符

    很好奇怎么实现在控制台中不换行直接显示新的信息把旧的替换掉,于是找到了两个ACII码字符,他们可以帮助实现. 一个是‘\b’字符,这个字符是backspace,即删除上一个字符,于是可以清除以显示的旧 ...

  8. Docker-镜像的操作命令

    2.镜像在Ubuntu中的一些命令 (1)docker image ls 列出镜像 能够罗列出docker中所以的镜像所在的仓库.镜像标签.镜像ID.镜像的创建日期.镜像的大小等等信息. (2)doc ...

  9. npx命令

    npx命令 查了一下, 英文资料: https://www.npmjs.com/package/npx 中文资料: 什么是npx 第一次看到npx命令是在 babel 的文档里 Note: If yo ...

  10. 如何用IE打开Chrome浏览器

    实现方式,用IE调用cmd命令打开chrome(注意:IE的ActiveX相关设置要启用) <script type="text/javascript"> functi ...