This is unmodified code from the Apple Utility Aplication template:
- (void)applicationDidFinishLaunching:(UIApplication *)application { MainViewController *aController = [[MainViewController alloc] initWithNibName:@"MainView" bundle:nil]; self.mainViewController = aController; [aController release]; mainViewController.view.frame = [UIScreen mainScreen].applicationFrame; [window addSubview:[mainViewController view]]; [window makeKeyAndVisible]; }
When mainViewController is assigned to aController , the self keyword is specified:
self.mainViewController = aController;
However, when the mainViewController frame is mainViewController , the self keyword is not required:
mainViewController.view.frame = [UIScreen mainScreen].applicationFrame;
If I remove the self keyword from the first example, the program crashes with the message:
objc[1296]: FREED(id): message view sent to freed object=0x3b122d0
If I add the self keyword to the second example, the program will work fine.
Can someone explain why self is required in the first case, but not in the second? I assume that in both cases the mainViewController refers to the same instance variable.
objective-c iphone cocoa-touch
Joe Mar 05 '10 at 10:24 2010-03-05 10:24
source share