Why does google suggest using trailing underscores when naming iVars in Objective-C?

The Google Objective-C Style Guide , which is followed by many people, Google says

Class member variables have underscores

Why? Are there any good reasons for this? I found that the apple is usually called ivar when underlining begins.

+8
objective-c naming-conventions trailing
source share
4 answers

Heavy Core Data users have also noticed that Core Data attributes cannot begin with characters other than alpha. If you want to consistently call ivars in your application and in different projects, this is another reason to add, rather than add your ivars with underscore.

If you don't use Core Data a lot, or you don't have OCD trends for consistency in naming conventions, then whatever works best for you is probably the right answer.

+5
source share

I prefer to track underscores, because if I have:

int test_; 

I can type 't' and it will immediately appear at the end of the code.

FROM

 int _test; 

I need to type '_t' to go to the end of the T code.

Whether this is true or not, I'm not sure, but I was convinced of this.

+25
source share

This may be a carryover from the C ++ manual. In C ++, leading underscores are reserved .

Their naming convention for objective-c ivars is consistent with C ++ private member variables.

+2
source share

This is just their preferred style. An underscore, whether it is a prefix or suffix, means that it is a private ivar, not a property or public ivar.

0
source share

All Articles