3
Answers

Explain lazy in Swift ?

Photo of Pravesh Dubey

Pravesh Dubey

6y
1.3k
1
When will be used lazy keyword in swift? and what are the advantages?

Answers (3)

2
Photo of Puneet Kankar
240 8.1k 1.1m 6y
Hi Pravesh,
 
A 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. 
 
Please check given below links for better understanding.
 
https://www.hackingwithswift.com/example-code/language/what-are-lazy-variables
 
https://medium.com/@abhimuralidharan/lazy-var-in-ios-swift-96c75cb8a13a
 
https://stackoverflow.com/questions/40694691/what-is-the-advantage-of-a-lazy-var-in-swift 
 
 
Accepted
1
Photo of Shweta Lodha
19 48.6k 4.2m 6y
Please mark it as an answer, if it has solved your purpose.
1
Photo of Shweta Lodha
19 48.6k 4.2m 6y
lazy variable is a keyword which can be used with function. These variables will be assigned a value only and only when function is called. This will save memory and processing of variables.