I have a very simple question, (Yes I am this new)
In various books and even in Apple's own Swift documentation I often see examples like this to check if an optional has a value.
My question is this. When I use this method aren't I essentially using/allocating more memory to create/store a new constant/variable ("MyVar" in this case) that all I'm using it for is to check an optional?
Or does Swift know that I'm just using it to check the Optional and just drop the constant/variable (and its value/stored reference) immediately after?
Edit: Reworded to try and better describe my intent....hopefully :/
In various books and even in Apple's own Swift documentation I often see examples like this to check if an optional has a value.
Code:
If let MYVar = SomeClass.SomeProperty? {
Print("Yay A value")
}
else {
Print("Sad No Value")
}
Or does Swift know that I'm just using it to check the Optional and just drop the constant/variable (and its value/stored reference) immediately after?
Edit: Reworded to try and better describe my intent....hopefully :/
Last edited: