My development environment:
Xcode 4.6.2
non-Automatic Reference Counting
For example, suppose we have a view controller called CertainViewController
, where a NSArray *
typed property called listData
has been declared, with attributes retain
and nonatomic
. listData
is to be loaded to a table view. I would do it like this:
// CertainViewController.h
@interface CertainViewController : UIViewController
{
}
@property (retain, nonatomic) NSArray *listData;
// CertainViewController.m
@implementation CertainViewController
@synthesize listData;
- (void) viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
// someValue is ready
self.listData = someValue;
// Release someValue
}
- (void) dealloc
{
self.listData = nil;
}
While some other developers would explicitly specify the instance variable _listData
for property listData
and do it like this:
// CertainViewController.h
@interface CertainViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
{
NSArray *_listData;
}
@property (retain, nonatomic) NSArray *listData;
// CertainViewController.m
@implementation CertainViewController
@synthesize listData = _listData;
- (void) viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
// someValue is ready
self.listData = someValue;
// Release someValue
}
- (void) dealloc
{
[_listData release];
}
Are the above two implementations totally equivalent? Or any tiny differences? The explicit appointing instance variable as _listData
just mean to be use [_listData release];
?
Any hint is welcome and thank you for help :D