I have defined a structure in one class interface. I have used it in that class properly. But I m not able to refer to this structure in other classes. I think I m missing some basics. Generally struct data type defined in one class should be accessible to all the classes in the project right? Why is this not working?
Asked
Active
Viewed 121 times
1
-
Possible duplicate of [Objective-C: Where to define macros to be avaivable everywhere?](http://stackoverflow.com/questions/5769959/objective-c-where-to-define-macros-to-be-avaivable-everywhere) – MishieMoo Aug 31 '11 at 17:18
2 Answers
2
If the struct is declared in your class .h file, you have to import the .h file wherever you need to access the struct.

jrturton
- 118,105
- 32
- 252
- 268
-
Thanks for answering. Is there any other way that does not need importing the file? – sridevi Aug 31 '11 at 17:15
-
1You can declare it in a completely separate file, if you don't want to import the class header, and import this file everywhere you need the struct. – jrturton Aug 31 '11 at 17:18
1
If you have definitions that need to be shared amongst several modules then it's best to place them in a separate, common header file and import that header file wherever needed. This design is clean and highly extensible.

Perception
- 79,279
- 19
- 185
- 195
-
How does this behave in other languages like c. There also do we need importing the file where struct is defined? – sridevi Aug 31 '11 at 17:21
-
It behaves the same way in C. And by the way, Objective C is just an extension/superset of C. – Perception Aug 31 '11 at 17:44