iOS 12 Programming for Beginners
上QQ阅读APP看书,第一时间看更新

Creating a mutable array

It is a best practice to make all arrays (and, for that matter, collections) immutable, but there are some cases where you will need to create an array that is mutable. Let's have some fun and create a mutable array:

var states:[String] = [] 

As an aside, when creating a mutable array (or any variable), note that each variable must be unique.

One use of a mutable array is so that we can add to the array. Let's look at some ways in which we can do this.