I frequently need to refer to an array of strings (let's say team names) in multiple places. The contents of that array to not change.
To achieve this, I defined my own class, MyConstants
. In the header I am defining some unrelated constant strings and numbers. In the implementation file, I made the class a singleton, and then added a class method arrayOfTeamNames
.
To access the array, I use [Constants arrayOfTeamNames].
I this acceptable?
I was thinking about how NSString and NSArray themselves handle creation via class methods. If, for example, I want an empty array, I can use [NSArray array]
- so presumably 'array' is a class method on NSArray.
Therefore, instead of my above implementation, should I be using a category to add '+arrayOfTeamStrings' to NSArray, instead of using my own class?
Or, alternatively, should I create my own subclass of NSArray and add the class method there?
In either case, do I need to make the class a singleton myself? Or is this not necessary?