简体   繁体   中英

How to declare a Swift Array

I'm trying to figure out my errors in a swift program it is my first program in swift and I'm learning the syntax. How would one declare an array in swift?

If you wish to declare an array in Swift there are two ways. The most popular and most idiomatic is to use square brackets around a type. For an Array of Ints you might have:

var myArrayOfInts : [Int]

This is syntax sugar for using the generic Array struct so you could equivalently write:

var myArrayOfInts : Array<Int>

Though I don't believe I have ever seen that written in any code (after the square bracket syntax was introduced) in any case that wasn't an example (just like this one) of how the two are equivalent.

你应该试试

 var temp = [Int]()

很简单

var myArray: [String] = []

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM