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 Build a Simple iPhone App with Swift Creating a Data Model Creating a Data Collection

Mathias Bakken
Mathias Bakken
3,167 Points

Using array subscripting, retrieve the string "bread" from the array and assign it to a variable named cart. Help!

I attempted to removeAtIndex() and I looked up documentation on subscripting. I made it work in both instances in my own playground, but I can't seem to move forward with the work on treehouse. Please Help!

data_collections.swift
var shoppingList = ["toothpaste", "bread", "eggs"]

if shoppingList.count > 0 {
    var cart = shoppingList[1]
}

1 Answer

Hi Matthias,

You're doing fine. There's no need for the conditional test.

var cart = shoppingList[1]

That should be fine!

Steve.

Gabe Nadel
seal-mask
.a{fill-rule:evenodd;}techdegree
Gabe Nadel
Treehouse Guest Teacher

Steve is right, you don't need the test to pass the code challenge, in fact putting that in there is why it's getting rejected. That said, it's good practice to checks of that flavor in the "real world".