I am a beginner, pls I need your opinion, what is difference b/w compute property and lazy property. I have learned compute property run everytime when i access however lazy property run ones on first access then stores (caches) the value .
A lazy variable is not cached. It’s a stored property, same as its non-lazy variant. The difference is when initialization happens. Lazy variables are initialized on first use, whereas non-lazy variables must be initialized explicitly, either as part of the declaration or as part of the type’s init. Global variables are inherently lazy because there is no init that can be invoked to initialize them.
In contrast, a computed property can be considered like syntactic sugar for a function call.
The LazyVGrid, is a good example of a lazy thing. It is a view that only loads and displays the child views that are needed, in order to optimize performance. When inside of a scroll view, or something else like that, the LazyVGrid will load and unload content dynamically, where as a Grid by itself would try to load all the content, even if it’s far off screen.
I forgot that you could add lazy as a property. It’s cool that you can stick it on variables, in addition to views. If I’m not mistaken.
The Medium article: “iOS Interview Question: Lazy Variables vs Computed Properties in Swift” has some information.