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 Object-Oriented Objective-C Tying it All Together Inheritance

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Compound Operators

Could use a little confusion cleared up. At ~13:00 Gabe uses the Compound Assignment Operator =+ in some of the code that was never used as the code block this was in was just an example of a way (not the best way) to do something. There was no error in Xcode, but I'm under the impression that it should have been +=.

Was his backwards because of a typo. I searched many documentations about this and every one shows +=. So, if it was a typo, why didn't Xcode throw up a 'red stop sign'?

Can anyone shed some light. :dizzy:

cc: Gabe Nadel

2 Answers

Here is the best that I can come up with. In objective-c the + is also a unary operator. It reads =+ as equals (+)unary (if you type it in to Xcode 7 with an objective-c project you will get the message "Use of unary operator may be intended as compound operator). Hope that helps!

Typo. I tried it in Xcode, and got the warning "Use of unary operator that may be intended a s compound assignment (+=)". This code ran:

    int x = 4;
    x =+ x;
    NSLog(@"%i", x);

but x was logged as 4, not 8.