When XCode creates synthesize statements in Apple's templates, you would see something like:

@synthesize ivar=_ivar;

So I get the single underscore, and how you name ivars differently than properties to make sure you don't accidentally access them, etc...

I just started a core data project, and in the template-created statements, I have:

@synthesize managedObjectContext=__managedObjectContext;

@synthesize managedObjectModel=__managedObjectModel;

@synthesize persistentStoreCoordinator=__persistentStoreCoordinator;

Why the double underscore for core data-related ivar names? Is this just an Apple syntax? Not sure if there is more to it than that and if it is something I need to be aware of - Google was not very helpful.

Thanks!

有帮助吗?

解决方案

The Objective C compiler treats all variable names the same, so a double underscore is merely a convention. However, a double (or single) underscore followed by a capital letter is reserved for use by the compiler.

Also, check the answers to this question, they are more in-depth than I can explain.

其他提示

Leading double underscores are supposed to be reserved exclusively to the compiler and language libraries. However Apple decided to also use them for Core Data. We mere mortal developers should not use double leading underscores.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top