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 trialAndrian Gungon
1,129 Pointsvariable with underscore
it's not clear to me why the float variable in this lesson has underscore(_)?
4 Answers
Stone Preston
42,016 Pointsits an objective c naming convention.
Andrian Gungon
1,129 Pointswhen to add underscore in a variable? or it is just a naming convention to add underscore when variable is float only?
Stone Preston
42,016 Pointswhenever you want. It is a convention to differentiate member variables from local variables. You dont have to name your variables like that. Its just a convention that a lot of people use.
Andrian Gungon
1,129 Pointsthank you so much sir Stone Preston, now I understand.
Stone Preston
42,016 Pointsyou might also see it when using properties. If I have a property named variable I can either access it directly using _variable or use the setter/getter methods variable and setVariable. When using properties, the _variable is generated behind the scenes.
Stone Preston
42,016 Pointsassuming it was syntesized as @synthesize variable = _variable. But you dont have to do that kind of stuff nowadays. So what I said before may not be true
Andrian Gungon
1,129 Pointsthanks again for added info.