I need to retrieve 6 questions from a plist and check the answer if is correct from the plist itself??
i will use a QR code scanner api to scan for answer, the api will covert to a string and read from the plist to check if the answer is correct... is there any tutorial or references for me to look @ ??
In my plist there is: question ~ Dictionary with the following strings:
NumberOfOption ~ which define if the question is a multipl开发者_开发知识库e choice or a QR code question Question ~ question itself Answer ~ Answer itself Option 1 ~ 4 ~ if it is a multiple choice question
Thanks in advance for answering my questions, i appreciated it
cheers
Desmond
Use the following code to read data into a array of Dictionaries (assuming your plist is in your main bundle)
// Path to the plist (in the application bundle)
NSString *path = [[NSBundle mainBundle] pathForResource:
@"questionArray" ofType:@"plist"];
// Build the array from the plist
NSMutableArray *qArray = [[NSMutableArray alloc] initWithContentsOfFile:path];
you can then iterate over your questions like:
// iterate questions
for (NSDictionary *dic in qArray)
{
//perform your reading of 'NumberOfOption' etc from dic object here.
}
Depending on how your plists are structured, you can read them in to memory using [NSArray arrayWithContentsOfFile:...];
or [NSDictionary dictionaryWithContentsOfFile:...];
. Beyond that, it really depends on how your plist is structured, how your input is coming in, etc.
I hope your 1.plist
has questions and 2.plist
has corresponding answers. In this case you should make your plists containing arrays only.
But in your case you have other information like option in your questions plist so you should go with the dictionary structure for this plist and make other plist an array. Following the array structure is really easy to access and store your questions, but in case of dictionary you should be little careful.
I would suggest that you should store the questions and answers with same corresponding keys in both the plists. Like for the question number 1 you use the key @"0" and for 2 use @"1" and so on. hence accessing answers from 2 will be the easier.
Hope this helps.
精彩评论