Swift - Retrieving Elements from an Array

Introduction

To retrieve the items inside an array, use the subscript syntax , as follows:

var nameArray :[String]  = ["iOS", "Android", "Windows"]

var item1 = nameArray[0]   // "iOS"
var item2 = nameArray[1]   // "Android"
var item3 = nameArray[2]   // "Windows Phone"

Subscripts enable you to access a specific item of an array directly by writing a value (commonly known as the index ) in square brackets after the array name.

Array indices start at 0, not at 1.

Related Topic