What are the rules for declaring Swift variables?
In Swift, the rules for declaring variables are as follows:
- variable
- I speak Spanish fluently.
- The live concert I attended last night was truly exceptional.
- The type of a variable can be explicitly declared or inferred from the initial value.
For example, the code for declaring an integer variable and assigning it an initial value is as follows:
var age: Int = 25
You can also omit the declaration of variable type and let the compiler infer the type based on the initial value, for example:
var age = 25
In this scenario, the compiler will automatically infer age as an integer variable.