Keeping things @class-y

June 29th, 2011
#xcode #errors

I run into the following error from time to time"

Expected specifier-qualifier-list before `XYZ`

and everytime it takes me a while to work out what caused it.

Making sure I don't forget πŸ™ƒ

It's caused by introducing an import circular dependance where class abc imports class xyz which imports abc - the compiler is then caught in an infinite import loop.

When we use #import we are copying that class's code into the importer's class whihc in turn copys it's imports, etc, until we get to the bottom of the stack. To prevent this copying of imports we need to use @class instead of #import. @class is a class-forwarder that promises that the class exists but doesn't attempt to actually import that class into the other class. By not importing the class we prevent a circular dependance from ocurring but don't lose our ability to include the @class class in our public method signatures and properties.

@class should be used in the .h file and #import in the .m file

What do you think? Let me know by getting in touch on Twitter - @wibosco