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

Brian Uribe
Brian Uribe
3,488 Points

What am I doing wrong?

What is wrong with this line of code?

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

I try entering it into the computer for the challenge question and I keep getting it wrong. Not sure why.

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

2 Answers

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

todo.append("Debug App")

todo.append("Fix Bugs")

///// OR/////

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

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

I feel 2nd method is better.

You're calling .append() with 2 arguments, when it only takes 1 argument. Break it down into two function calls with one argument each, and you're good to go.

Brian Uribe
Brian Uribe
3,488 Points

Oh! Okay! Is there a way to do it with two arguments?

You can do this:

var numbers: [Int] = [0]
numbers += [1, 2]
// numbers: [0, 1, 2]