Basics: Type Safety and Type Inference
If you don’t specify the type of value you need, Swift uses type inference to work out the appropriate type.
Enables a compiler to deduce the type of a particular expression automatically when it compiles your code, simply by examining the values you provide.
Is particularly useful when you declare a constant or variable with an initial value.
Additional information
- Because Swift is type safe, it performs type checks when compiling your code and flags any mismatched types as errors. .
- Type-checking helps you avoid errors when you’re working with different types of values. .
- Swift always chooses Double (rather than Float) when inferring the type of floating-point numbers.
Semantic portal