I realize this question is pretty basic, but I’m really stuck. I have a plist. I’m trying to read that into an array so I can work with it in various classes. So in one class I have:
+ (NSArray*)questionArray
{
static NSArray* questions = nil;
if(!questions)
{
NSString *path = [[NSBundle mainBundle] pathForResource:@"Questions" ofType:@"plist"];
NSDictionary *dic = [[NSDictionary alloc] initWithContentsOfFile:path];
NSArray *questionsArray = [dic objectForKey:@"groups"];
NSMutableArray *questionObjects = [[NSMutableArray alloc] initWithCapacity: [questionsArray count]];
for(NSDictionary* questionDic in questionsArray)
{
QuestionContainerObject* object = [[self alloc] initWithDictionary:questionDic];
[questionObjects addObject:object];
[object release];
}
questions = questionObjects;
[dic release];
}
return questions;
}
I want to be able to access the things I pull out of the array from another class. I tried calling it like NSString *str = [QuestionContainerObject questionArray]; from my other class (after importing the header) but I get the ‘class method +questionArray not found’ warning.
Can someone please point me in the right direction? I’m really lost! Thanks!!
The warning is because the compiler does not know the questionArray method exists.
define this method in the header (QuestionContainerObject.h)
and in the file using it:
Also remember to release objects created using [class alloc]