Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

47云:swift的lazy #50

Open
platojobs opened this issue Sep 18, 2021 · 0 comments
Open

47云:swift的lazy #50

platojobs opened this issue Sep 18, 2021 · 0 comments
Labels
Technology technology
Projects

Comments

@platojobs
Copy link
Owner

  • lazy 修饰符,lazy属性
  • lazy 方法, 集合的一个方法

lazy属性就是初始值直到第一次使用的时候才执行计算的属性
注意:lazy属性必须是变量(var修饰符),因为常量属性(let修饰符)必须在初始化之前就有值,所以常量属性不能定义为lazy

延迟加载主要有以下两个使用的场景

  1. 属性的初始值依赖于其他的属性值,只有其他的属性值有值之后才能得出该属性的值。
  2. 属性的初始值需要大量的计算。
@platojobs platojobs added the Technology technology label Sep 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Technology technology
Projects
No open projects
PJ技术类
Awaiting triage
Development

No branches or pull requests

1 participant