Accessing and Modifying Arrays

So, you have a bucket list? Great! Sadly, you do not have all that many ambitions in there yet. But you are an interesting person with a zeal 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(_:) function 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 bucket list

Add more future adventures to your bucket list using ...

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.