April 2026
Intermediate
683 pages
25h 29m
English
A quantity is a measurable property of an object. Length and weight are common examples; for example, a television may be two meters wide and weigh five kilograms, highlighting two quantities related to a TV.
As evident in the last example, a quantity consists of two parts:
A numerical value, such as 2 or 5
A unit of measurement, such as meters or kilograms
Because the value and unit always go hand in hand, Swift empowers us with standardized data types to manage those in tandem, as we’ll discuss in this section. Let’s start with the core concept of units.
A unit represents the type of measurement, such as meters, grams, Celsius, bars, degrees, and so on. Swift provides several predefined Unit subclasses ...
Read now
Unlock full access