Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Swift 2.0 Basics Swift Operators Unary Operators

Edward Bromley
Edward Bromley
3,353 Points

Deprecation of ++ and --

It appears that Apple plans to remove these operators. https://github.com/apple/swift-evolution/blob/master/proposals/0004-remove-pre-post-inc-decrement.md

Should the video reflect this?

Sebastian Nitu
Sebastian Nitu
8,616 Points

Yes, that is correct. Starting with Swift 2.2, the postfix operators ++ and -- will be depricated.

You can learn more about the upcoming Swift changes here: http://ericasadun.com/2015/12/03/changing-swift-whats-coming-up-in-2-2-and-3-0/

1 Answer

Michael Hulet
Michael Hulet
47,842 Points

The ++ and -- operators are deprecated in the latest version of Swift, and will be removed entirely in Swift 3.0, coming this Fall (assuming you live in the Northern Hemisphere. Otherwise, Spring). That being said, Swift is still a rapidly evolving language, and will continue to be as such for a long time, though a lot of stuff should be finalized with Swift 3, because that update will come with ABI stabilization. Because of that, my personal vote is towards adding teachers notes right now, and then recording new videos with Swift 3

Now that Swift 2.2 has been released, it would probably be good for the teacher's notes to be updated. It would be nice if the associated task were updated to support the alternative syntax as well.

Laura Ross
Laura Ross
Courses Plus Student 2,449 Points

I agree with Nathan. I can't figure out how += 1 is replacing ++. The auto-fixes suggested by the compiler are

x = ++b is now x = b += 1

and

x = b++ is now x = b += 1

Can someone explain the correct replacement?

Michael Hulet
Michael Hulet
47,842 Points

I wrote a far more detailed answer over here