views:

12

answers:

2

Hi, I tried to understand the three20 ttnavigator example code, and in the MenuController.h file, it is as follows:

typedef enum {
  MenuPageNone,
  MenuPageBreakfast,
  MenuPageLunch,
  MenuPageDinner,
  MenuPageDessert,
  MenuPageAbout,
} MenuPage;

@interface MenuController : TTTableViewController {
  MenuPage _page;
}

@property(nonatomic) MenuPage page;

@end

I don't understand why there is a MenuPage _page declared as an instance variable, while there is another variable MenuPage page declared in the @property section. In the MenuController.m file, MenuPage page is synthesized, not _page.

Is this legal?

I know it works, because it compiles, but I don't understand why we don't need to set an @property (nonatomic, retain) MenuPage _page or declare MenuPage page in the interface.

Thanks!

A: 

This line in MenuController.m

@synthesize page = _page;

connects the property to the ivar. (It tells the compiler to use the _page ivar to store the value of the page property.)

Robot K
A: 

Thank you, but why would we want to separate the ivar from the property if we're going to set them equivalent at synthesis?

Jon