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

Creating an array with initial values

Arrays can have initial values when they are created. Let's see how this would look by entering the following in Playgrounds:

let integers2 = [54, 29]  

Your code will now look like this:

The array that we just entered uses type inference to declare the data type of the array using its initial values. In this case, Swift understands that it is an array of ints because the values we entered are integers. In addition, when we use a constant (let) on an array, we are telling Swift that the array is an immutable array, which means that the contents or size cannot change once it is instantiated.