O'Reilly logo

Swift Programming: The Big Nerd Ranch Guide by John Gallagher, Matthew Mathias

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required