Type annotation in Swift

Type Annotation is used to provide information about the type of values stored by the constants and variables. Mostly we don’t have to use type annotation as Swift can infer the type of values stored in its variables and constants.

Example:

let textTwo: String = “Come let us learn Swift”

In the above code, constant textTwo is of type String.

Type annotation is written by placing a colon after the name, followed by a space and then the type of value stored by the variable/constant.Type of constant and variable cannot be changed once they are declared.

Leave a Reply