I'm writing a quiz application for iPhone using basic NSObject
subclasses to represent the models. At runtime the various controllers instantiate the model classes and populate them with data read in from a plist on the disk.
The model classes represent the basic hierarchy of a multiple choice quiz:
- One application has many quizzes
- One quiz has many questions
- One question has many answers
Currently, when the QuizController
class loads its Quiz
object, it populates its questions
NSArray
property with Question
instances, and as each of those Question
instances are initialized, they each initialize their own NSArray
s of Answer
instances.
I recognize that I don't need every question in memory when I load a quiz, I only need a question at a certain index in the Quiz
instance's questions
array.
I'm thinking that some sort of dataSource protocol or lazy loading pattern would help reduce the memory footprint incurred when loading up any particular quiz on this system, but I'm unsure how to implement either. I'd really appreciate any suggestions that the community had in terms of:
What pattern would be appropriate to use here? A short code snippet would also be hugely helpful for me to understand how I might begin to implement it.