views:

163

answers:

3

In Xcode, I have a forward class declared so as to avoid a circular import e.g.

@class MyClass;

And then I do a method call on that class e.g.

[MyClass myMethod];

But I get a forward class warning e.g.

warning: receiver 'MyClass' is a forward class and corresponding @interface may not exist

How can I hide those across my whole project?

A: 

have you imported the class in your implementation of class?

Eimantas
This is to avoid importing in the case where I have two classes that need to call each other so that there is not a recursive import. I merely want to suppress the warning.
Matt Williamson
There is no such thing as a recursive import. The whole point of #import is to prevent recursive #includes. You can have each header #import the other with no problems, and you don't need to use @class at all.
cdespinosa
+15  A: 

You use forward class declarations in your header file to prevent circular imports.

You must still import the MyClass header in your .m file. The circular import problem doesn't exist with .m files.

Darren
+2  A: 

My answer to a similar question may be of use here.

The basic concept is this:

use @class in header files, and then use #import in the .m files.

e.James

related questions