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 Swift 2.0 Collections and Control Flow Control Flow With Loops While and Repeat While

Michael Boswell
Michael Boswell
2,363 Points

++ vs += in Swift 3

Xcode is reminding me every time I write ++ to increment to switch it to += 1 for Swift 3.

Question:

Given this change to the syntax, how would I write it before said variable is incremented?

Example:

count++ becomes count += 1 ++count becomes _____?

3 Answers

Michael Boswell
Michael Boswell
2,363 Points

Isn't that like saying count++, not ++count?

Seth Kroger
Seth Kroger
56,413 Points

This one has confused people since the creation of C. Strictly speaking, count += 1 is equivalent to ++count, but not quite the same count++. They all add one count but first two evaluate the new value of count while count++ evaluates to the old value. There's little difference you're only incrementing, but a big one if you're using it inside an expression.

Found this interesting doc from Chris Lattner on the ++ deprecation: https://github.com/apple/swift-evolution/blob/master/proposals/0004-remove-pre-post-inc-decrement.md

So it seems they are just going to remove ++ from swift 3, any idea if it going to get replaced? Because I been getting the caution sign that they are going to be no more in swift 3 in Xcode.