Swift - Lazy Property (lazy var)

#I. <b> INTRODUCTION </b>
Hey , Today our topic will be <b>lazy property</b>. Some people they known it as lazy var. So if we talk about the lazy property, we will think about the <b> memory used by application </b> .What do I mean by <b>"Memory Used by application" </b> ? Well , When you develop an application of course we have to create object , variable , etc... to store the user data or input. So if you are developing a small or medium application I think you are going to be ok but if you develop a large or complex application I am sure you will face the memory issue problem if you are not consider about the memory allocation.

#<b> II. " Lazy Property? What is that ? " </b>
Apple official document say:  <B><i> "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. " </B> </i>


to make above statement more clear please see the example code below.

```swift
struct InterviewCandidate {
    var isiOS:Bool?
    
    lazy var iOSResumeDescription: String = {
        return "I am an iOS developer"
    }()
    lazy var androidResumeDescription: String = {
        return "I am an android developer"
    }()
}

var person1 = InterviewCandidate()
person1.isiOS = true

if person1.isiOS! {
    print(person1.iOSResumeDescription)
} else {
    print(person1.androidResumeDescription)

}
```
So in above code , as you can see. 
1. We have 1 struct name <b>InterviewCandidate</b> which has <b>1 Bool variable and 2 lazy var </b> as it property.
2. We have the struct property object name <b> person1 </b>.
3. During <b> if else statement </b>. it is going to invoke the lazy var name <b> IOSResumeDescription</b> and it will return "I am an IOS developer" as its value. On the other hand the value of another lazy var which name <b> androidResumeDescription </b> will be <b> nil </b>.

####<b> why? why nil? </b> 

because as you can see the above code , the <b> if statement </b> is true so the <b> lazy var iOSResumeDescription </b> going to initialize when the program execute <b> print statement</b> and the program is not going to execute <b> else statement </b> so it is not going to invoke <b>lazy var androidResumeDescription</b>. By doing that you could save the memory allocate of lazy var androidResumeDescription.

#<b>III. Conclusion

So by using lazy property you could save memory by avoiding memory used by application if it is not needed.

##<b>Lazy Rule<b>
1. You must always declare a lazy property as a variable (with the var keyword), because its initial value might not be retrieved until after instance initialization completes. Constant properties must always have a value before initialization completes, and therefore cannot be declared as lazy.
2. You can’t use lazy with let .
3. You can’t use it with computed properties . Because, a computed property returns the value every time we try to access it after executing the code inside the computation block.
4. You can use lazy only with members of struct and class .
5. Lazy variables are not initailize atomically and so is not thread safe