(NSArray *)allItems method


For clarification why do implement this? If someone could explain why that would be greatly appreciated.



Specifically the method in BNRItemStore.m

- (NSArray *) allItems 
    return allItems; 


allItems the instance variable belongs to an instance of BNRItemStore.

In order for another object - like, ItemsViewController - to see that array, the BNRItemStore must be able to return a pointer to allItems in a public method. This is that public method.


Thanks for the clarification.

So we do it this way so other methods can get a readonly version of the data of the array, but not modify the data. This is why we don’t set up allItems as a @property (which then while it would be public, other methods in turn could change the array). Right?



Yes, it is returning an “immutable” array for something that only the store can mutate. (Altho, not technically true, because if someone typecasted it to a mutable array, allitems would still be a NSMutableArray and they could modify it… but that is bad style.)