Variables

Variables

var str = "ABCD"
//str is the name of the variable

after declaring, can change value:
str = "Hello"

To make the variable a constant (error when someone changes it)
let str = "ABC"
//Not used that often
//Useful when you are working in teams

Swift infers types.
To indicate type explicitly:

var str: String = "ABCD"
var mynum: Int = 8
//integer, no decimal place

var myNum: Double = 8.55
//contains decimals
//Double has a fixed number of decimal points - 15

var myNum Float = 8.55
//fewer number of decimal points, not as accurate

var trueOrNot: Boolean = true
//can also be false





Notes
- 3rd iteration of swift.
- Comes after Swift 2, Swift and Objective C.
- Objective C is not compatible with Swift.
- Swift, Swift 2 and Swift 3 - might not be compatible, needs to change references.
- Current Swift 3 should be compatible with future versions.

Comments

Popular posts from this blog

Setting up a playground

Go to another page