Advanced Swift language features
Generally, interviewers like to start up softly with Swift features, checking different language aspects and trying to locate any red flags we might have about Swift.
In this section, we will go through more advanced features of Swift, beginning with computed and lazy variables.
Solving computed and lazy variables questions
Computed and lazy variables are both advanced features of Swift variables, providing efficient ways to improve performance and code readability.
First, let’s be aligned about what computed and lazy variables are:
- Computed variable – a variable that calculates its value based on other properties, doesn’t store its value in memory, and calculates it every time it’s accessed
In the following Rectangle
class, area
is a computed variable that is based on width
and height
values:
class Rectangle { var width: Double var height: Double...