Generally speaking, when should you make a variable in Objective C an instance variable?
For instance, say I got an UIViewController with an UILabel. In what cases would I have the UILabel as an instance variable vs doing something like this:
UILabel *label = [[UILabel alloc] init];
//set text of label
[view.addSubview label];
[label release];
In your particular example, the object is written as a variable so that it can be sent a
releasemessage after adding it to a view (which retains it).The equivalent code without a variable is:
We don’t need to send a release, because we’re autoreleasing the object.