Using pointer to change navigationItem title


on page 234 in ItemsViewController.m we modified the init method to change the navigationItem title to Homepwner by using a pointer

- (id)init { .... UINavigationItem *n = [self navigationItem]; // we are creating a pointer to the navigation item itself [n setTitle:@"Homepwner"]; // we changed the value .... }

later in the page we updated the DetailViewController by overriding the setItem method and setting the navigationItem title property again (for the detailView title) but we accessed the property without creating a pointer

- (void)setItem: (BNRItem *)i { item = i; [[self navigationItem] setTitle:[item itemName]]; // accessed navigationItem directly and sent it the message }

these both have the same result but from a best practices and performance perspective which is better? why choose one over the other and under what circumstances.


I have received some feedback on stackoverflow. Apparently when you don’t use a pointer the compiler generates a hidden temp pointer anyways so they are the same thing, the benefit to separating statements 1 per line and using intermediate variables is for when applications become complex and require time debugging and this makes it easier to filter through.