It's unusual to need to subclass any of the collection classes that the Foundation framework provides (NSArray, NSDictionary, NSSet, NSMapTable, etc. and their mutable variants). In fact, it's so unusual that if you think you need to do it, your first move should be to carefully think about why you need to do it, and then sleep on it. (If you want to see someone take a shot at it, check out Mike Ash's recent article on reimplementing NSMutableArray.) The reason that it's so unusual to subclass a collection class is that the collection classes already implement the behaviors required by the standard data structures that they represent: NSArray gives you an indexed list of objects; NSDictionary gives you an associative array; and so on.
From your comments, it sounds like you might be well served by some combination of containers. It's difficult to tell exactly what you want from your description, so I'll have to make some assumptions (which I'll try to state) and hope that even if they're wrong, you may still be pointed in the right direction. So, let's say that you've got a list of questions, and for each question you have an answer and some number of clues. In that case, you might choose to use a dictionary to represent each question. The dictionary could have three keys: 'question', 'answer', and 'clues'. The values associated with the first two keys could just be strings, and the value for 'clues' might be an array or set of strings. And since you've got some number of questions, you'd store each of those dictionaries in a common array. In JSON format, it'd look like this:
[
{
"question" : "What's the capitol of New York?",
"answer" : "Albany",
"clues" :
[
"It's not New York City.",
"It's near the Hudson river.",
"Its name begins with 'A'."
]
},
{
"question" : "What's the state sport of Maryland?",
"answer" : "jousting",
"clues" :
[
"If you try it, you'll need a horse and some armor.",
"Kids, don't try this at home."
]
}
]
You could build this up programmatically if you wanted to, but since it's all just static data you'd do better to use the Property List Editor to create the data. Then you can just read it into an array using +arrayWithContentsOfFile:
.
Now, about that singleton... It sounds like you really just want an object that'll hold your data and which is easy to access. So, create a class that can contain the array described above:
@interface QAModel : NSObject
@property (strong) NSArray *questions;
+ (QAModel*)sharedModel
@end
@implementation QAModel
@synthesize questions = _questions;
+ (QAModel*)sharedModel
{
if (self.sharedModel == nil) {
sharedModel = [[QAModel alloc] init];
}
return sharedModel;
}
- (id)init
{
if ((self = [super init])) {
_questions = [NSArray arrayWithContentsOfFile:pathToMyDataFile];
}
return self;
}
@end
This gives you a shared model object that's easy to access. It's not a true singleton since it doesn't prevent you from instantiating it more than once if you really want to, but that's not usually what people are after when they talk about using a singleton.
Note that the only subclass here is a simple subclass of NSObject -- the arrays and dictionaries are right off the shelf.