Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Swift Basics (retired) Collections Modifying an Array

var todo = ["Learn Swift", "Build App", "Deploy App"] todo.append("Debug App","Fix Bugs") What,s wrong in this code ?

I have type an append in but it say,s it,s a wrong assignment code.

What is wrong with it ?

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

2 Answers

Jhoan Arango
Jhoan Arango
14,575 Points

Hello:

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 (+=):”

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

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

both of these codes work for your challenge.

Great ! thanks , this is a very clear answer...