“Lazy” keyword — Swift 5 (iOS)

What is lazy? When to use it? Is it safe?

Source — Self😎

Declaring lazy

fullName — a lazy member declared as var
A User class with a simple lazy property to simulate a heavy computational task (inefficient)

Suspend task

All the heavy computation is done at the time of initialization
No computations are performed and the user is initialized

Avoid re-computations

heavyComputation is a computed property
Calling the property heavyComputation 2 times
A lazy property heavyComputation is accessed 2 times

When not to use lazy

iOS Developer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store