Friday, February 19, 2010

Forward Declarations in Objective C

Wow. Somehow I missed this.

Forward declarations in Objective C are implemented via the @class directive. In general, #import shouldn't be used in header files to bring in other classes in the application; import these only in the implementation file. In header files, use @class instead, which merely tells the compiler that the listed names are names of classes declared elsewhere. Not following this advice can lead to an assortment of maddening error messages, most of which have to do with cyclical class dependencies (the error message "expected specifier-qualifier-list before", for example.

No comments: