I’ve created an 3 objects, and chained them together:
- Questionnaire object – which contains a
- NextQuestion object – which contains an
- Answer object – which has an text property.
In a ViewController, I want to be able to call:
NSString *thisAnswerText = Questionnaire.nextQuestion.answer.text;
However, to do this, I have to import all three files into my .m file
#import "Questionnaire.h"
#import "Question.h"
#import "Answer.h"
Is it necessary to import each of the objects that I use in each .m file? Or is there something I can do which means I only need to import the top level item and all it’s children are automatically referenced?
NB. I know that I can add all three to the Prefix.pch file, but I was wondering if I’m missing some trick to Objective-C which allows me to declare one item and it’s child objects become imported automatically?
THANK YOU!
When you import a .h file any imports within the .h file are also available. You may need to clean and rebuild but they should be available. So in your case no, you should be able to get away with importing the
Questionaire.honly.Also if you’re app depends on those custom classes and they will be used all over the place, it can be a good idea to import them in your .pch file and they will be precompiled for all your classes.