Reputation: 1112
What is the difference between below declaration of array syntax in swift?
var arr:[Int]
var arr=Array<Int>()
and which one is better? How and Why?
Upvotes: 2
Views: 127
Reputation: 107
var arr:[Int] This one simply declares an array of Integers named arr. It does not initialise the array and hence is not usable.
var arr=Array() This one declares as well as initialises the array. We can add whatever we want to this arr.
The second one is better since its initialised and usable.
Upvotes: 0
Reputation: 257
var arr:[int] this is fixed size array and don't change size after initialization.
var arr=Array() this is array list and this array change the size with respect to number of elements. you can easily remove and add element easily in this array.
Upvotes: 1