Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I continue to use iVar and @property (nonatomic, retain) plus @synthesize under Automatic Reference Counting (ARC)?

Like a doop I'd been declaring Instant Variables (iVar) and then @property in the interface .h file for a while now.

@interface MainGameViewController : UIViewController {
     UserFactorsViewController *userFactorsViewController;
     UITableView *myTableView;
}
@property (nonatomic, retain) UserFactorsViewController *userFactorsViewController;
@property (nonatomic, retain) IBOutlet UITableView *myTableView;

Under Automatic Reference Counting, should I just dispense with iVar and go all @property? Should I even have the word "retain" in property? What if I'm deploying for iOS 4.3, should I still use ARC?

like image 299
Ben Avatar asked Aug 23 '11 16:08

Ben


1 Answers

Don't feel like a doop, even though the compiler will add ivars for you if you don't include them, many people still declare them (many book authors as well) to make the code a little bit easier to read (easier to distinguish between ivar and property).

When creating a property now, Apple wants you to think in terms of Object Graphs, so do some research on "strong" and "weak" property attributes instead of retain and releases.

Also, iOS 4 is setup as a target for ARC so you should be ok. But I believe if you wanted to support iOS 3.0 you would have to manually manage retain and releases as before.

like image 172
5StringRyan Avatar answered Oct 16 '22 06:10

5StringRyan