Syntax

Swift Create an Array Syntax

In Swift, create an array: creates an ordered list — var nums = [1, 2, 3] nums.append(4)

Quick Answer

Syntax
var nums = [1, 2, 3] nums.append(4)
SwiftSyntax

Create an Array

Code example
var nums = [1, 2, 3] nums.append(4)

Creates an ordered list.

Learn More

How to create an array in Swift

  1. Open your Swift file or editor.
  2. Copy the example, then replace its sample names and values for your code.

Swift Create an Array Syntax

Use var nums = [1, 2, 3] nums.append(4).

Related Syntax References

Frequently asked questions

What is the Swift syntax for create an array?

Use this pattern: var nums = [1, 2, 3] nums.append(4)

Can I copy this Swift code example?

Yes. Use Copy code and adapt the example to your program.

Is this Swift syntax different on Mac or Windows?

No. The language syntax is the same across operating systems.

Official source · How we verify