differing methods of alloc / init / retaining an object in objective-c
- by taber
In several pieces of sample objective-c code I've seen people create new objects like this:
RootViewController *viewController = [[RootViewController alloc] init];
self.rootViewController = viewController; // self.rootViewController is a (nonatomic,retain) synthesized property
[viewController release];
[window addSubview: [self.rootViewController view]];
Is that any different "behind the scenes" than doing it like this instead?
self.rootViewController = [[RootViewController alloc] init];
[window addSubview: [self.rootViewController view]];
Seems a bit more straightforward/streamlined that way so I'm wondering why anyone would opt for the first method.
Thanks!