I'm a beginner and I sort of understand Lazy Var vs. Let. I've noticed that it saves a ton of memory usage when using Lazy Var especially with ImageViews. But the tutorials and guides I've seen so far don't use Lazy Var very often, so I'm feeling suspicious that it is bad practice and that I'm overlooking something.
I did a little research and learned that Lazy isn't "thread safe," but I don't understand what this means. I've seen a lot of pros and cons, but I can't draw any conclusions especially because I have very limited knowledge.
When is it ok (or better) to use Lazy Var vs. Let when creating a UIView?
lazy var profileImageView: UIImageView = {
let imageView = UIImageView(image: #imageLiteral(resourceName: "page1"))
imageView.translatesAutoresizingMaskIntoConstraints = false
imageView.contentMode = .scaleAspectFit
return imageView
}()
lazy var
is. Specifically look at the section on when to use it: mikebuss.com/2014/06/22/lazy-initialization-swift Now, looking through the three related links in the right hand column of your question that suggest they are similar to your's I find that none really answer the question - like the above link - on *when to use each one. They either explain whatlazy
is (and why you have to usevar
or why something doesn't build. I'm up-voting this hopeing that somebody here can give you a good answer to a good question