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 Displaying Data with Table Views in Swift 2 Enhancing the Networking Stack Foursquare Endpoints

Tony Teixeira
Tony Teixeira
14,823 Points

advancedBy no longer available

Since advancedBy is no longer available in Swift3 is there a better way to advance than:

return commaSeperateString.substring(from: commaSeperateString.index(commaSeperateString.startIndex, offsetBy: 1))

it seems quite repetitive.

Jeff Ripke
Jeff Ripke
41,989 Points

Here is what I came up with:

return commaSeparatedString.substring(from: commaSeparatedString.index(after: commaSeparatedString.startIndex))
Keenan Turner
Keenan Turner
6,270 Points

Tony Teixeira Yeah I got to this problem and saw that things have changed. And even though Jeff Ripke has given the correct answer I wanted to understand this a bit more.

After looking online I found this article that explains that Strings are now responsible for managing their indexes.

Article here--> http://www.swift-studies.com/blog/2016/6/17/swift-30-string-index-changes

Which means that commaSeparatedString.substring can handle the index move with the new syntax. Here are examples of how the new syntax has changed things:

myString.index(after:) // returns an index advanced by one
myString.index(before:) // returns an index reduced by one
myString.index(currentIndex:,offsetBy:) // returns an index moved offsetBy characters

I hope this helps!

-Keenan