OK, this must have been asked before but I looked like mad and found nothing:
I have a simple array in my iphone app which I define like so:
@property (nonatomic, strong) NSArray *pages;
@synthesize pages = _pages;
I’ve seen this in Apples sample code and thought this is a nice short-cut for writing self.pages (i.e. _pages replaces self.pages) like so:
_pages = [[NSArray alloc] init];
but then Apple has this again (not exactly like this, but it appears as if they keep swapping randomly):
self.pages = [NSKeyedUnarchiver unarchiveObjectWithData:contents];
And finally:
[_pages release];
Which totally confuses me. What would be the difference between _pages and self.pages?
Thanks for your help.
_pagesis the name of the object’s ivar.pagesis the property name which is different.So,
@synthesize pages = _pages;finally tells thatpagesis the property for the ivar_pages.You will encouter the ivar direct access via
_pagesin initializers and dealloc methods. Every where else, the property name is used to get/set its value.