In Swift, you declare an array using square brackets and optionally specify the type.
In this example,
numbers
of type [Int]
and initialize it with some values.let numbers: [Int] = [1, 2, 3, 4, 5]
print("Array elements:", numbers)
Array elements: [1, 2, 3, 4, 5]
In this example,
values
of type [Double]
and initialize it with some values.let values: [Double] = [1.1, 2.2, 3.3, 4.4, 5.5]
print("Array elements:", values)
Array elements: [1.1, 2.2, 3.3, 4.4, 5.5]
In this tutorial, we learned How to Declare an Array in Swift language with well detailed examples.