Are lazy vars in Swift more than once? I got the impression that they replaced:
if (instanceVariable) { return instanceVariable; } // set up variable that has not been initialized
The paradigm from Objective-C (lazy instance).
Is that what they do? As a rule, only once at the first request of the application it requests a variable, and then just returns what was calculated?
Or does it receive a call every time, as a normal computed property?
The reason I'm asking is because I basically want Swift to compute a property that can access other instance variables. Let's say I have a variable called "fullName", and it just combines firstName and lastName . How do I do this in Swift? It seems that lazy vars are the only way to go, as in normal computable vars (not lazy), I cannot access other instance variables.
So basically:
Are lazy vars in Swift called more than once? If so, how do I create a computed variable that can access instance variables? If not, if I want the variable to be computed once for performance reasons, how do I do this?
lazy-initialization swift computed-properties
Doug Smith Oct. 19 '14 at 20:02 2014-10-19 20:02
source share