Swift 2 changes
Page content
####Structs are value types
classes are reference types
- print()
Array:
eg:
var arr:Array<Int> = []
or
var arr:[Int] = []
for mixed values you have to explicitly mention:
var mixed:[Any] = [1, "str", false]
var mixed:[AnyObject] = [1, "str"]
mixed.append(2, atIndex:3)
mixed.insert(2, atIndex:3)
mixed.remoteAtIndex(2, atIndex:3)
.. all the way upto … all the way upto and including ..<
Array Slicing:
Array enumerate() to get the index
####Dictionary 2 ways of declaring: eg:
Optionals:
var x: Int? x = 12 var y:Int?
if x != nil { print("(x!)") }
//Optional binding (shortcut for above) if let z = x { print("(z)") }
if let xx = x { if let yy = y { print(xx*yy) } }
// in swift 2 - multiple conditions in one line if let xx = x, let yy = y { print(xx*yy) }
if let xx = x where xx % 2 == 0 { print(xx) }