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

Jaskirat Singh
Jaskirat Singh
1,652 Points

What?

What is wrong With THIS?

data_collections.swift
var shoppingList: [String] = ["toothpaste", "bread", "eggs"]
var cart = shoppingList.removeAtIndex[1]

4 Answers

Caleb Kleveter
MOD
Caleb Kleveter
Treehouse Moderator 37,862 Points

Getting rid of removeAtIndex will solve the problem:

var cart = shoppingList[1]
Jaskirat Singh
Jaskirat Singh
1,652 Points

It worked! can you please briefly explain me how that is the subscripting method?, or why that is working and what I did is not?

Caleb Kleveter
Caleb Kleveter
Treehouse Moderator 37,862 Points

Not really. In the challenge instructions it says to 'Using array subscripting'. When you use removeAtIndex though you get an error in the preview that says:

swift_lint.swift:5:12: error: '(Int) -> String' does not have a member named 'subscript'
var cart = shoppingList.removeAtIndex[1]

So I don't think that once you removing 'removeAtIndex' you are subscripting. I might be wrong though.

Josh Gonet
Josh Gonet
5,602 Points

HI Jaskirat. I believe it's because the 1 after 'removeAtIndex' needs to be in regular brackets instead of square brackets. Change that and see if it helps!

Josh

Jaskirat Singh
Jaskirat Singh
1,652 Points

It says

Bummer! You need to use subscripting to access the array element.

Josh Gonet
Josh Gonet
5,602 Points

Which value are you trying to remove: toothpaste, bread or eggs?

Jaskirat Singh
Jaskirat Singh
1,652 Points

if you click on data_collections on top of the code I wrote on the top, it will take you to the challenge. I am getting stuck at the 2nd task