Hi Readers!
There are different ways to declare Array in Swift. I will write few examples below:
Example 1:
let a : Array? = ["hello","hi"]
Now in above example this is a constant array. You cannot add/append an element in it.
Example 2:
Below both versions of declaring array are same
var a2 = Array<String>()
var a3 = [String]()
Example 3: This will declare an NSArray. Here you cannot add an element. And this array contains NSObjects.
var a3 = ["hello",12]
Example 4: This will declare a NSMutableArray. You can add elements in it similar to Objective c
var a3 = [] as NSMutableArray
0 Comment(s)