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 trialJonathan Halbrook
3,853 PointsWhy is the challenge compiler rejecting my code when it compiles on playground?
On challenge task 3 of 4 for inserting and deleting values in Swift Collections and Flows the result of my code below was "Bummer! Your code could not be compiled." Preview gave this error message ( swift_lint.swift:11:12: error: expression resolves to an unused l-value arrayOfInts[4] ).
It compiles properly on Xcode so is there some type of bug in the challenge compiler or am I just not seeing my mistake?
Task 3 of 4 - We also learned about reading values from an array. Retrieve the 5th item (remember array indexes start at 0) and assign the result to a constant named value.)
My code - var arrayOfInts = [2, 4, 6, 8, 10, 12]
arrayOfInts.append(14)
arrayOfInts += [16]
arrayOfInts[4]
let value = arrayOfInts[4]
Thanks for your help!
2 Answers
Moritz Lang
25,909 PointsHi, the following code did work for me:
var arrayOfInts = [0, 34, 57, 54, 89, 456]
arrayOfInts.append(56)
arrayOfInts += [19]
let value = arrayOfInts[4]
// task 4
let discardedValue = arrayOfInts.remove(at: 5)
Your mistake has to be writing arrayOfInts[4]
in one line as this isn't valid Swift code. You can use this however in Playgrounds to get immediate results. In a real Xcode project this would be wrong code and you'd get a compiler error.
Jonathan Halbrook
3,853 PointsThanks so much! After I took out the line "arrayOfInts[4]" everything worked.