Search code examples
objective-cnaming-conventionsunderscore.jstrailing

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


In Google's Objective-C Style guide which is follow by many people , Google says

Class member variables have trailing underscores

Why? Is there any good reason for doing this? I found apple usually name an ivar when beginning underscore.


Solution

  • Heavy users of Core Data will have also noticed that Core Data attributes cannot begin with non-alpha characters. If you want to name ivars consistently across your app and various projects, this is another reason to append, rather than prepend, your ivars with an underscore.

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