Accessing and Modifying Arrays
So, you have a bucket list?
Great!
Sadly, you do not have 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.
var bucketList = ["Climb Mt. Everest"] ["Climb Mt. Everest"] bucketList.append("Read War and Peace") ["Climb Mt. Everest", "...
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.
Arguments are data given to a method for it to work with; you will learn more about them in Chapter 12, Functions.
The sidebar shows the value of bucketList
Get Swift Programming: The Big Nerd Ranch Guide, 3rd Edition 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.