Home > Software engineering >  Swift array access by index
Swift array access by index

Time:10-30

One quick question about swift arrays. I defined my array in swift as follows

var merge: [Int] = [Int]()

And when I try to add value into it using index as below

 merge[0] = 88

I am getting array out of index exception. Can someone please explain me what is happening here. ?

CodePudding user response:

That is how you set the initial value of dictionary not an array. You can append or insert elements to an array.

https://docs.swift.org/swift-book/LanguageGuide/CollectionTypes.html

merge.append(88)

You can modify existing values with the methodology you are using but not create.

  • Related