I'm making an iPad app that will display a few choices and based on your choice will display a series of questions with each question triggering a different set of questions. I was wondering if there was a name for this or any open-source library that someone has made for this kind of app.

If not, would it be best to hard code all the questions and responses into the app, or to read them from a file?

  • Have you checked the Storyboard? – Ramzi Kahil Jul 18 '12 at 23:03
  • @Martin Each view will look virtually identical, so I was hoping to use the same view for each step. So storyboard doesn't really make sense for my app. – edc1591 Jul 18 '12 at 23:23
  • CAT (Computerized adaptive testing)? "CAT successively selects questions so as to maximize the precision of the exam based on what is known about the examinee from previous questions. From the examinee's perspective, the difficulty of the exam seems to tailor itself to his or her level of ability...." – gnat Aug 18 '12 at 1:04

This is a tree.

Your nodes are the questions, and each question has as many children as there are answers to it. Your session context contains the current question, and it leaps forward by asking a new one.


We could also say that this tree is a directed bipartite graph with each question node connecting to multiple answers, and each answer node connecting to exactly one question node.

A good storage would be, for example, XML:

<question id='3'>
   How are you?
      <answer next_question_id='4'>Fine, thx</answer>
      <answer next_question_id='5'>Badly</answer>
<question id='4'>
   Boy or girl?
      <answer next_question_id='8'>Boy</answer>
      <answer next_question_id='9'>Girl</answer>
<!-- ...-->

Or, if you want to keep the tree visualized, you could try YAML:

    title: How are you?
    answers: [
          text: Fine, thx
               title: Boy or girl?
               answers: [
          text: Badly

A session might look the following:

web sequence

So, how it is implemented MVC-wise is a different matter.

You have similar things in adventure games (infocom games) btw, but that's much more advanced.

Edit: this thing is called a Dialog Tree, and you can find answers on StackExchange as well.


What kind of framework do you really need? A few view controllers, some nicely-laid-out views, and a sensible way to represent the data: you're done. If you're having trouble seeing how to write such a thing, I'd suggest that you start by deciding how to organize the data:

  • What's a question?
  • Are questions organized into groups?
  • How does the answer to one question affect the question that the program asks next?

"Twenty questions"-like programs have been around for decades. Here's some ancient BASIC source code for Animals. And here's output, thanks to Jeff Atwood's article on a similar theme. Back when personal computers were very new, question-and-answer games were some of the first programs that were used widely in classrooms.

Also very old are text-based adventure games where the player is presented with a situation and a number of options. These kinds of programs aren't very different from the kind of thing you're describing.

So, all this is to say that the structure of your program is probably going to be pretty simple -- I doubt you'll need a framework to get you there.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.