NOTE: using 2nd edition Chapter 21
I don’t seem to be the first person to be confused by the example in which a NSMutableArray instance variable is declared alongside a NSArray property in BNREmployee.h. Apologies if this has been discussed to death already. Hopefully, this is a nuanced take on the question. For the sake of experimentation, I
- got rid of the NSMutableArray instance variable
- changed the property from NSArray to NSMutableArray
- removed the explicit accessors in the .m file
and everything seemed to work fine.
I did this for the sake of curiosity, because it seemed like the intuitive way to write the code, and I was actually kind of shocked that there were no consequences, not even any compiler warnings. Are there in fact consequences to taking this “lazy” approach in more complex code? Are these topics revisited or elaborated on in further chapters? Up until this point in the book, everything seemed to make lots of sense and was essentially intuitive. This was the only part that felt like, “do it this way because we say so.”