Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Swift Basics (retired) Collections Modifying an Array

Daniel Walsh
Daniel Walsh
309 Points

We need to append a few more items to our todo array. Append the following strings: "Debug App", "Fix Bugs".

Anyone know where I am going wrong with this? I thought they wanted me to enter in the todo.append tag but now I am not sure.

arrays.swift
var todo = ["Learn Swift", "Build App", "Deploy App"]
todo.append("Debug App", "Fix Bugs")

1 Answer

Jhoan Arango
Jhoan Arango
14,575 Points

Hello Daniel:

There are 2 ways you can append or add an item into your array.

First : “You can add a new item to the end of an array by calling the array’s append method”

This only allows you to add ONE item at a time

var todo = ["Learn Swift", "Build App", "Deploy App"]

todo.append("Debug App")
todo.append("Fix Bugs")

Second : “Alternatively, append an array of one or more compatible items with the addition assignment operator (+=):”

Excerpt From: Apple Inc. “The Swift Programming Language.” iBooks. https://itun.es/us/jEUH0.l

var todo = ["Learn Swift", "Build App", "Deploy App"]

todo += ["Debug App","Fix Bugs"]

both of these codes work for your challenge.

Daniel Walsh
Daniel Walsh
309 Points

Thanks man! That helped a lot!