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
Amin Shariati
4,092 PointsError while using remove method
While following practice shown on the video on Swift 3 Collections and Control Flow I wrote the following code:
// Arrays
var todo: [String] = ["Finish Course", "Start next course", "Shopping"]
todo.append("Write a line of code")
todo += ["drive a car", "check sms"]
todo.insert("Buy fish", atIndex: 0)
// Removing items from array
todo.remove(atIndex: 0)
but I am getting the following error on todo.remove(atIndex: 0):
Playground execution failed: Collection and Control Flow.xcplaygroundpage:17:1: error: value of type '[String]' has no member 'remove'
todo.remove(atIndex: 0)
As per the video the remove method should exist whereas in my case it's not there. Any idea what is happening?
By the way If I replace the code with
todo.removeAtIndex(0)
then I will get the expected result.
1 Answer
luke jones
8,915 PointsIs this in the simulator or playground?
todo.removeAtIndex(0)
is swift 2 syntax, where as
todo.remove(at: 0)
is swift 3
Amin Shariati
4,092 PointsAmin Shariati
4,092 PointsI am using it in Playground.
Thanks didn't know it was a version related issue. So the training examples are based on Swift 3.0 and my Xcode is using the old Swift.