Chapter 6 : Type Annotations

Type Annotations

When you declare a variable or a constant in Swift you do not need to explicitly specify what datatype it belongs to. But if you want to define datatype for a variable or a constant, you can do it using Type Annotations

In the below example, constant myInt is a variable of type Integer and myString is a constant of type String.

In the below example, we have tried to assing myInt of type Integer a String value and myString of type String a is a Integer value, resulting to errors.

Type does not confirm to protocol error