6.5 Adding and Removing Array Elements

Type Array provides various methods and operators (Fig. 6.4) for adding elements to and removing elements from variable Arrays.

Image

Fig. 6.4 | Methods and operators for adding elements to and removing elements from Arrays.

Figure 6.5 demonstrates the methods and operator in Fig. 6.4. Function displayIntegers (lines 4–7) is used throughout the example to display:

• its Int Array argument’s contents.

• the Array’s read-only count property—the number of elements currently stored in the array.

• the Array’s read-only capacity property—the total number of elements the Array can store without reallocating its memory ...

Get Swift™ for Programmers now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.