14.3 Working with Arrays in Swift
Once an array exists, a wide range of methods and properties are provided for working with and manipulating the array content from within Swift code, a subset of which is as follows:
A count of the items in an array can be obtained by accessing the array’s count property:
var treeArray = ["Pine", "Oak", "Yew"]
var itemCount = treeArray.count
print(itemCount)
Whether or not an array is empty can be identified using the array’s Boolean isEmpty property as follows:
var treeArray = ["Pine", "Oak", "Yew"]
if treeArray.isEmpty {
// Array is empty
}
A specific item in an array may be accessed or modified by referencing the item’s position in the array index (where the first item in the array has index position 0) using a technique referred to as...