find the length of an array in swift

To find the length of an array in Swift, you can use the count property of the array. Here's an example:

main.swift
let array = [1, 2, 3, 4, 5]
let length = array.count
print(length) // Output: 5
80 chars
4 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.

related categories

gistlibby LogSnag