Overview - Explicit type annotation
What is it?
Explicit type annotation means telling the Swift compiler exactly what type a variable or constant should have. Instead of letting Swift guess the type from the value, you write the type yourself after the name. This helps make your code clearer and safer by avoiding confusion about what kind of data is stored.
Why it matters
Without explicit type annotation, the compiler guesses types, which usually works but can sometimes cause mistakes or unclear code. Explicit types prevent bugs by making your intentions clear and help others understand your code quickly. It also helps when the compiler cannot guess the type or when you want to use a more general or specific type than the default.
Where it fits
Before learning explicit type annotation, you should understand variables, constants, and basic types in Swift. After this, you can learn about type inference, optionals, and generics, which build on knowing how types work in Swift.