To find the length of an array in Swift, you can use the count
property of the array. Here's an example:
main.swift80 chars4 lines
In this example, we've created an array with five elements, and then used the count
property to get its length. The output in this case is 5
.
Note that the count
property is only available on Array
types in Swift, and cannot be used with other collection types like Set
or Dictionary
.
gistlibby LogSnag