1

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?

1

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for answering. Is there any other way that does not need importing the file?
You 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.
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.

2 Comments

How does this behave in other languages like c. There also do we need importing the file where struct is defined?
It behaves the same way in C. And by the way, Objective C is just an extension/superset of C.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.