Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When to use `self` in Objective-C?

It's now more than 5 months that I'm in Objective-C, I've also got my first app published in the App Store, but I still have a doubt about a core functionality of the language.

When am I supposed to use self accessing iVars and when I'm not?

When releasing an outlet you write self.outlet = nil in viewDidUnload, instead in dealloc you write [outlet release]. Why?

like image 729
Francesco Avatar asked Dec 27 '22 15:12

Francesco


1 Answers

When you write self.outlet = nil the method [self setOutlet:nil]; is called. When you write outlet = nil; you access variable outlet directly.

if you use @synthesize outlet; then method setOutlet: is generated automatically and it releases object before assigning new one if you declared property as @property (retain) NSObject outlet;.

like image 125
Nekto Avatar answered Dec 30 '22 03:12

Nekto