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. Vue模拟酷狗APP问题总结

    一.NewSongs.vue中的38行  this.$http.get('/proxy/?json=true')   里面这个路径的获取 二.router文件夹中的index.js  中的  comp ...

  2. poj 2762 Going from u to v or from v to u? 【 强连通 拓扑排序】

    给出n个点,m条边,问是否任意两点u,v,是否满足u能够到达v,或者v能够到达u 自己写的时候以为缩一下点,然后再判断一下能不能拓扑排序就可以了 但是--wa--- 后来看了这篇题解 http://e ...

  3. iOS性能优化未阅文章归档

    https://www.aliyun.com/jiaocheng/349583.html https://www.2cto.com/kf/201706/648929.html 理解UIView的绘制 ...

  4. luogu P2000 拯救世界 生成函数_麦克劳林展开_python

    模板题. 将所有的多项式按等比数列求和公式将生成函数压缩,相乘后麦克劳林展开即可. Code: n=int(input()) print((n+1)*(n+2)*(n+3)*(n+4)//24)

  5. jQuery优化性能的十种方法

    1,总是从ID选择器开始继承 例如: <div id="content"> <form method="post" action=" ...

  6. Python笔记27----时间解析

    1.将时间字符串解析成真正的时间 time.strptime http://www.runoob.com/python/att-time-strptime.html 代码: import time s ...

  7. php数组 匹配键值

    1.array_search() //判断键值是否在数组中,//存在,返回值对应的键;//不存在,返回false;//例子:$type = array( "选考" => 'o ...

  8. [Codeforces 115E]Linear Kingdom Races

    题目大意: 有n块地,初始是荒地.你可以把某些荒地开垦(需要花费相应的价值\(a_i\)(正整数)),然后这些荒地就可以种田. 现在有m年,每年要在l到r区间内种田,获得p(正整数)的价值(必须保证l ...

  9. 最全mysql的复制和读写分离

    mysql的复制和mysql的读写分离从来就不是一个简单的话题,今天笔者就详细来记录一下我学习的mysql.   mysql日至类型有:二进制日志,事务日志,错误日志,一般查询日志,中继日志,慢查询日 ...

  10. 2015 Multi-University Training Contest 6 hdu 5358 First One

    First One Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total ...