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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.