Friday, 3 July 2015

Variable declaration in Swift

Declaration of iVar:

Let's start with declaring iVars in Swift

In Swift we can declare an iVar using keyword:
1. let - it declares an immutable iVar
2. var - it declares a mutable iVar

let myLetObject = "My immutable iVar"
So now i cannot change the value of myLetObject after it is once assigned.

var myVarObject = "My mutable iVar"
myVarObject = "Changed the value of iVar"
I can change its value at any instance.

Some examples of declaring objects:
let luckyNumber = 9
let myAge = NSInteger(27)
var myHeight = 5.5
let myImage = UIIMage(named:"MyPhoto.png")
var myName: NSString = NSString"string:Suraj Ramjan Mirajkar"
var tableView: UITableView!

1 comment:

  1. Hello Dear sir

    I like your blog very well, I want to say thank you for giving so good information.
    I have a website We provide payment gateway
    Payment Gateways