Can you explain to me on what they are used for and some examples
A type annotation is a way to specify the type of a variable or constant by adding a colon followed by the type name after the variable or constant name.
For example, to declare a variable as a string, you can use the following syntax: var message: String = "Hello, World!"
In this example, message
is a variable of type String
that has been set to the value “Hello, World!”.
Similarly, you can use type annotations to declare a constant as an integer: let numberOfApples: Int = 5