Francesco Francesco - 2 months ago 5
Objective-C Question

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

accessing iVars and when I'm not?

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


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;.