I have spotted an example in book: “iOS4 Programming Cookbook” that I can’t understand:
Tray *newTray = [[Tray alloc] initWithPrinter:self];
paperTray = [newTray retain];
[newTray release];
I can’t understand why we need a newTray variable. Why we couldn’t just use this code:
paperTray = [[Tray alloc] initWithPrinter:self];
Tray is just a Model Class. paperTray – property: Tray *paperTray;
You don’t need the
newTrayvariable at all. The alternate code you posted would be equivalent, and less verbose.The author may have included the other variable just to make it clear precisely what
[[Tray alloc] initWithPrinter:self]does.