I am seriously confused about the Objective-C #import.
I searched and found several tutorials saying that if I have lots of constraints like
#define val1
#define val100
it’s better to put all constraints in one file and import this file for reusing all values.
But i am still confused, I saw many code samples which #import all other files’ headers in which there is is no
#define constraints
These two files are normal UIViewControllers, but their headers are imported.
#import viewcontroler1.h
#import viewcontroler2.h
- When can we simply create objects of classes why import them?
- Where to import files in .h or .m?
- What to import, the .h or the .m file in Objective-C?
I am seriously confused, please help me.
I’m not sure I’m really understanding what you’re asking for, but you should avoid importing header files in other header files, if you don’t need to. Instead,
#importthe headers you need in the.mfile and use the@classdirective in your.hfiles instead.From the Apple docs:
Otherwise, you might be exposing your imported variables to more classes than you actually need. If you’re importing your
constants.hinviewcontroler1.h, any other class importingviewcontroler1.hwill also haveconstants.h. Sometimes this might be what you need, but it usually isn’t.Hope that helped in some aspect…