In Swift, capacity
is a property of an array. It gets the total number of elements that the array can contain without allocating new storage.
arr.capacity
This method takes no parameter.
It returns an integer value.
// create arraysvar gnaam = ["Google", "Netflix", "Amazon", "Apple", "Facebook", "Meta"];var letters = ["a", "b", "c", "d", "e"];var numbers = [1, 2, 3];// print number of elementsprint(gnaam.capacity);print(letters.capacity);print(numbers.capacity);
gnaam
, letters
, and numbers
.capacity
property of arrays.