When reading apple generated template code as well as in documentation, I see _
(underscore) and __
(double underscore). Example would be the code generated on checking off core data option:
@synthesize window = _window;
@synthesize managedObjectContext = __managedObjectContext;
@synthesize managedObjectModel = __managedObjectModel;
@synthesize persistentStoreCoordinator = __persistentStoreCoordinator;
What does each of this mean? I understand _
refers to a backing private variable. What does __
mean?
Apple's documentation suggest NOT to use single underscores in your project (as it reserved by apple itself: best-known example is _cmd ). But underscore is traditional c-style modifier for privateness of identifier, so double underscore is a solution to make private identifier for your variable.
Names of most private methods in the Cocoa frameworks have an underscore prefix (for example, _fooData ) to mark them as private. From this fact follow two recommendations.
Don’t use the underscore character as a prefix for your private methods. Apple reserves this convention.