Reputation: 815
I've been asked to develop a multiple-choice-test iPhone app. The test has six categories, each category has maybe 25 to 30 questions. The user selects a category and then is presented which the questions, one at a time. Each question includes 4 possible answers; there is a brief explanation provided if the user selects the wrong one. I'm working off of a word doc (I guess it could be a text doc or even a pdf) that looks like the standard type of multiple-choice test we've all taken. Any advice as to how to read, parse and display the questions and answers? Reading through the various Guides, how-to's, sample code, etc., it's not at all obvious (at least not to me) how to get it done. I'm sure it's obvious to all of you that I'm rather new at this. Any suggestions would be greatly appreciated.
Upvotes: 0
Views: 2923
Reputation: 73936
I'm making a few assumptions here:
Given those assumptions, using a plist is probably the best approach for storing the questions.
Add a new file to your project, under Mac OS X > Resource
you will find Property List
. Don't worry, OS X and iOS property lists are the same.
When you open this file, you will see that you can create arrays, dictionaries, string values, etc. Your exact format will depend on your app, but roughly speaking:
From there, you can load all of your data with something like the following:
NSString *path = [[NSBundle mainBundle] pathForResource:@"questions" ofType:@"plist"];
NSArray *categories = [NSArray arrayWithContentsOfFile:path];
The categories
object is a normal array and will reflect the contents of your plist. So, for example, to loop through categories and log the names, you'd do:
for (NSDictionary *category in categories) {
NSLog(@"%@", [category objectForKey:@"Title"]);
}
Where you go from there depends on exactly how you want your user interface to work, but using a UINavigationController
is probably a good start if you are completely stuck.
Upvotes: 2
Reputation: 33782
Im not sure whats your question is
Here is how to read a text file line by line.
Or reading a pdf as text. There are plenty of options out there. You should start coding and find resources as you proceed.
Upvotes: 1
Reputation: 4515
If working with an xml file is an option, go with that, in alternative you may want to take a look at yaml which offers a nice syntax. A more laborious alternative would be to set up a web application for your customer to submit questions and then to generate the xml directly from there.
Upvotes: 0