Swift – Create Array with Initial Values

To create an Array with initial values in Swift, use square brackets. Get all the initial values, separated by comma, in the opening and closing square brackets. This is our Array with initial values. We may assign it to a variable.


In the following program, we create an Int Array with initial values: 2, 4, 6 and 8.


var someEvenNumbers = [2, 4, 6, 8]
print("Array : \(someEvenNumbers)")


Array : [2, 4, 6, 8]

Similarly, we could create Array of any type with required initial values of that type.

Now, let us create an Array with initial values: “United States”, “India”, “Russia”, “China” and “Japan”.


var someCountries = ["USA", "India", "Russia", "China", "Japan"]
print("Array : \(someCountries)")


Array : ["USA", "India", "Russia", "China", "Japan"]


In this Swift Tutorial, we learned how to create an Array with initial values.