Accessing and Modifying Arrays

So, you have a bucket list? Great! Sadly, you do not have that many ambitions in it yet. But you are an interesting person with a zest for life, so let’s add some values to your bucketList. Update your list with another ambition.

Listing 9.5 Hot air balloon adventure

import Cocoa

var bucketList = ["Climb Mt. Everest"]
bucketList.append("Fly hot air balloon to Fiji")

You are using append(_:) to add a value to bucketList. The append(_:) method takes an argument of whatever type an array accepts and makes it a new element in the array.

Your playground should look like Figure 9.1.

Figure 9.1 Appending to your bucketList

Get Swift Programming: The Big Nerd Ranch Guide now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.