When I first read Beginning iOS 3 Development before ARC, I remember seeing patterns like this in some ViewController class:
.h
@property (nonatomic, retain) NSArray *myArray;
.m
in viewDidLoad:
NSArray *tempArray = [[NSArray alloc] init];
self.myArray = tempArray;
[tempArray release];
I remember reading that you did this so the properties could handle the memory for you if you used the property setters/getters. So now with ARC, I’m wondering if you still follow that kind of variable creation. For example, if you start a new project in iOS 6, in the AppDelegate, they do
.h
@property (strong, nonatomic) ViewController *viewController;
.m
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
The temp variable is not created in this case. I was wondering why and if I should be following that pattern instead of the first one. Thanks!
They are the same pattern except now ARC properly handles the release for you. The 2nd block of code is just fine with ARC. That’s what makes ARC so nice.