Swift - Appending Elements to an Array

Introduction

To append an item to an array, use the append() function:


var OSes :[String]  = ["iOS", "Android", "Windows"]
OSes.append("Tizen")

The array now contains the appended element:

Alternatively, you can also use the += operator to append to an array:

OSes +=  ["Tizen"]

You can append an array to an existing array:

Demo

var OSes :[String]  = ["iOS", "Android", "Windows"]
OSes += ["Symbian", "Bada"]
print(OSes)

Result

Related Topic