Search code examples
objective-csynthesize

In Objective-C, what does the code after an @synthesize mean?


Sorry for the bad title, I wasn't sure what else to call this question. Anyways, suppose I have the following:

@synthesize display = _display

My question is what is the difference between display and _display? What does each refer to?

To clarify, I know what @synthesize does (it creates getters and setters) but I'm not sure exactly what the difference what display and _display refer to.

I'm proficient at java, so whenever possible relate your answer to it.

Thanks


Solution

  • display is the name of the property. It also affects what the getters and setters will be called.

    _display is the underlying field in the object which the property will access. Some people like to leave it the same as the property -- this behavior occurs by default, so it's easy; some people like to prefix their fields with underscores. (Some crazy people also like to use completely different names, but they're crazy.)