Tuesday, 4 October 2016

Variables and Type conversion

Variables

When you know you will need to change some data, you have to use a variable.

var variableNumber: Int = 420
You have to declare constants using let and  variables using var.
Type Conversion 
Sometimes you will have data which need to be converted it to another format.
var first: Int = 1000 // variable first with int value 1000

var second: Double = 122.5 // variable second with value 122.5
first =  Int(second) // Type conversion of second to Integer

Constants

In this Blogpost, you'll learn constants.

You will learn, how to declare, name and change them. 

You'll also learn about type inference (Swift's most important features).

Constants

let firstConstant: Int = 100 

This declares a constant called 
firstConstant which is of type Int. 
Then it sets the value of the firstConstant to the number 100.

let  
piConstant: Double = 3.141

This is similar to the above constant, except the name and the type are different. 
This time the constant is a Double.

Once you've declared a constant, you can not change its data