InterviewSolution
| 1. |
What do you mean by lazy property in iOS? |
|
Answer» LAZY properties are properties whose initial value isn't computed until the first time they are used. Including the lazy modifier/keyword before the DECLARATION of a stored property indicates it is lazy. This lets you delay the initialization of stored properties. This could be a great way to streamline your code and reduce unnecessary work. When a code is expensive and unlikely to be called consistently, a lazy variable can be a great solution. Example: class PERSON { var name: Stringlazy var personalizdgreeting : String = { RETURN “HelloScala \(self.name)!” }() INIT(name: String) { self.name = name } }As shown above, we aren't sure what value personalizedgreeting should have. To know the correct greeting for this person, we need to wait until this object is initialized. |
|