A single pointer to multiple objects


I was surprised to see the stock pointer used to point to two different dictionary objects. Is this something that all pointers can do (pointing to multiple objects) as long as the objects are of the same class? My second question is why you used stock = [NSMutableDictionary dictionary]; rather than stock = [[NSMutableDictionary alloc]init]; ? Are there any rules as to when to use one format over the other to create an object?


Answer #1: Yes, it is pretty common to use a pointer to put to several different objects in turn. The most common case? When you are iterating through a collection of objects, you typically have a pointer to the one you are currently “processing”.

Answer #2: If you are using ARC, there is no difference between [[NSMutableDictionary alloc] init] and [NSMutableDictionary dictionary].