Swift Language Arrays

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Introduction

Array is an ordered, random-access collection type. Arrays are one of the most commonly used data types in an app. We use the Array type to hold elements of a single type, the array's Element type. An array can store any kind of elements---from integers to strings to classes.

Syntax

  • Array<Element> // The type of an array with elements of type Element
  • [Element] // Syntactic sugar for the type of an array with elements of type Element
  • [element0, element1, element2, ... elementN] // An array literal
  • [Element]() // Creates a new empty array of type [Element]
  • Array(count:repeatedValue:) // Creates an array of count elements, each initialized to repeatedValue
  • Array(_:) // Creates an array from an arbitrary sequence

Remarks

Arrays are an ordered collection of values. Values may repeat but must be of the same type.



Got any Swift Language Question?