1

I'm having some error on the following relationship

I have 2 classes, Class A and Class B inside Class A header, it will #import "B.h" inside Class B header, it will #import "A.h"

I'm having error during compilation. Anyone know how can I resolve this?

Error looks something like this: expected specifier-qualifier-list before 'GameUILayer'

Cadrick Loh
  • 721
  • 1
  • 7
  • 19
  • possible duplicate of [Objective-C header file not recognizing custom object as a type](http://stackoverflow.com/questions/7896440/objective-c-header-file-not-recognizing-custom-object-as-a-type) also http://stackoverflow.com/questions/7091778/import-in-objective-c-am-i-doing-this-wrong, http://stackoverflow.com/questions/1223914/objective-c-import-loop – jscs Dec 07 '11 at 05:36

2 Answers2

1

Instead of importing the headers in the .h files, use forward declarations. So instead of

#import "ClassA.h"

you use:

@class ClassA

etc

and then you use the import statement within the .m files.

See my earlier answer for the link to the documenation.

Community
  • 1
  • 1
Abizern
  • 146,289
  • 39
  • 203
  • 257
1

You're creating a circular dependency. One class should import the other. They can't both import each other. If you're making interacting classes like that, there should be a hierarchy of dependence. B depends on A, A depends on, at a minimum, the root class NSObject. If you make two classes dependent on each other, the compiler can either yell at you or try to compile it and end up running around in circles. Most compilers are designed to yell at you.

wbr
  • 81
  • 5