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. LeetCode224. Basic Calculator (用栈计算表达式)

    解题思路 用两个栈分别存字符和数字. 顺序读入字符,处理方式分为字符和数字两种. 处理字符分为')'和非')'两种. 处理数字需要读取字符栈栈顶,分为'+'.'-'和非'+'.'-'. 代码 clas ...

  2. leetcode525. 连续数组 python

    给定一个二进制数组, 找到含有相同数量的 0 和 1 的最长连续子数组. 示例 1: 输入: [0,1] 输出: 2 说明: [0, 1] 是具有相同数量0和1的最长连续子数组. 示例 2: 输入: ...

  3. 路飞学城Python-Day22

  4. Day 01 计算机编程基础

    1.编程语言是什么? 编程语言是人与计算机交流的介质 2.什么是编程? 用编程语言写出一个个文件,这堆文件会达到一个目的 3.编程有什么用? 让计算机帮助我们干活,从而解放人类劳动力 4.计算机组成原 ...

  5. C# 鼠标左右手切换

    using System; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServi ...

  6. HDU 1086 You can Solve a Geometry Problem too( 判断线段是否相交 水题 )

    链接:传送门 题意:给出 n 个线段找到交点个数 思路:数据量小,直接暴力判断所有线段是否相交 /*************************************************** ...

  7. CF833B The Bakery (线段树+DP)

    题目大意:给你一个序列(n<=35000),最多分不大于m块(m<=50),求每个块内不同元素的数量之和的最大值 考试的时候第一眼建图,没建出来,第二眼贪心 ,被自己hack掉了,又随手写 ...

  8. Shell(四)函数

    函数 linux shell 可以用户定义函数,然后在shell脚本中可以随便调用. 一.格式 shell中函数的定义格式如下: [ function ] funname [()] { action; ...

  9. 基本配置及安全级别security-level

    interface GigabitEthernet0/0 nameif outside  //指定接口名称 security-level 0  //安全级别设置 ip address 1.1.1.2 ...

  10. 【codeforces 738E】Subordinates

    [题目链接]:http://codeforces.com/problemset/problem/738/E [题意] 给你一个类似树形的关系; 然后告诉你某个人头顶上有多少个上司numi; 只有fat ...