Create an Empty Array in Swift

There are different ways of creating an empty array in Swift. Mostly because you can specify a data type of elements that an array can hold.

An Array of Integers.

let myArray = [Int]()

Another way to create an empty array

let myArray2 : [Int] = []

Create an Empty Array of String type

let myArray3 = [String]()

An Array of Dictionary type

let myArray4 = [Dictionary<String, String>]()

For more Swift code examples and tutorials, please check the Swift Code Examples page on this website.


Leave a Reply

Your email address will not be published.