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!



Comments

Popular posts from this blog

UITableView - Add or Remove Rows Dynamically (Objective C & Swift Source codes)

payUmoney Payment Gateway Integration in iOS App (Objective C)

Check Internet Connectivity Using AFNetworking 2.0