arkilis
10/13/2017 - 10:23 PM

Swift array

Swift array

// Create immutable array
let fooList = ["a", "b", "c"]
print(fooList.count)    // => a
print(fooList.first!)   // => c
print(fooList.last!)    // => a
print(fooList[1])       // => a


// Create a mutable array
var fooMutableList : Array = ["a", "b", "c"]
//var fooMutableList = ["a", "b", "c"]
fooMutableList.append("d")		 
print(fooMutableList.last!)		// => d
print(fooMutableList.count)		// => 4
fooMutableList.remove(at: 2)
print(fooMutableList.count)		// => 3


// Common methods for swift immutable and mutable array
// 1. Size
let fooList = ["a", "b", "c"]
print(fooList.count)    // => a


// 2. First and Last element
let fooList = ["a", "b", "c"]
print(fooList.first!)   // => c
print(fooList.last!)    // => a

// 3. Check existence
let fooList = ["a", "b", "c"]
print(fooList.contains("a"))   // => true