Swift comes with a number of basic types that are at the root of all of your programs. All of your programs leverage these basic types, one way or another. Let's take some time to revisit these types and their main features, along with some hidden gems.
We can organize all of the Swift's basic types into the following categories:
- Logical types:
Bool
- Numeric types:
Int
,Double
, andFloat
, among others - Range types:
Range
andClosedRange
- Errors:
Error
protocol - Optionals:
Optional
enum
I don't believe it's necessary to introduce the Bool
, Int
, Double
, and Float
types, as they are all very common in all languages. Perhaps their most interesting feature is that they are defined as structs
, and not primitive types, like in Java.