I have been having some trouble lately with using custom classes as types. As described in the title, I have been getting compile errors similar to the one below:
expected specifier-qualifier list before 'MyClass'
My code is usually something along the lines of this:
@interface MyCoolClass : NSObject {
MyClass *myClassObject; // Error is on this line.
}
I also occasionally use something like this:
@interface MyCoolClass : NSObject {
IBOutlet MyClass *myClassObject; // Error again on this line
}
Im not really sure if that is good to use but on occasion, I have done something like that so I could connect my objects together with Interface Builder so that one object could invoke a method on another object.
I’ve been able to do this before successfully with other projects but when I tried to do it today, it gave me this error. Any ideas what could be causing it? As far as I can tell, I have done the same thing that I did in the other project here.
It is also to my understanding that this error usually gets thrown if the type is not defined, but I am pretty sure that I have defined it.
Oh, GCC how obtuse and opaque can your errors possibly be….
Try compiling with the LLVM 2.0 compiler. It’ll give you much more sane errors.
In this case, what is usually going on is that the compiler doesn’t have a clue what
MyClassis or there is a syntax error in the previously included header file that doesn’t cause a compilation error until the @interface is hit in the file spewing the error.It could also be a misspelling.
Or, as suggested, you need to #import “MyClass.h” into the header file (or implementation file or, even better, the PCH file) so that MyClass is defined before the iVar declaration.
That’ll also do the trick.