It will take about 1 minutes to finish reading this article.
In Swift, we use the lazy keyword before the property to simply implement delayed loading, for example:
1 | lazy var str: String = { |
This style of writing is similar to closure, but it is actually an kind of anonymous function. We can use anonymous functions to initilize data. As shown below, it is an anoymous function creation call operation:
1 | { |
We can try to print the type of this type.
1 | func test() { |
The result is:
1 | () |