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 trialjosh garcia
332 PointsArray item into a constant
So far I have an array list and I've already taken out the item "Deploy App" but not i need to set "Deploy App" into a constant named item. how do i set it to a constant?
var todo = ["Learn Swift", "Build App", "Deploy App"]
todo += ["Debug App" , "Fix Bugs"]
todo.removeAtIndex(2)
let todo.
2 Answers
Jhoan Arango
14,575 PointsHey Josh:
Very simple, remember the first part of swift basics how they showed you how to declare a constant or variable? Itβs basically the same concept.
// First we use the word βletβ to declare a constant, then we give it a name
let item =
/*
Then we give that constant the value, in this case it comes from an item being
removed from an array, so we capture it and set it into a constant.
*/
let item = todo.removeAtIndex(2)
Good luck, if you need more help please let me know by tagging me with @jhoanarango
Josue Gisber
Courses Plus Student 9,332 PointsSince the function removeAtIndex() return a type as we learned in the video, what you have to do is capture that item that is being remove by assigning it to a constant named item. Like This: Let item = nameOfArray.removeAtIndex()...... Whatever name of the array you have and between (), type the index you wish to remove and it will be stored @ the constant item. Hope this make it clear for you!