views:

161

answers:

2

I am trying to build the Clustering Plug in my project under Leopard. I have following two questions.

In the project an interface class is defined as

@interface ClusteringController : NSWindowController
{
.......
.....
....
}
@end.

And this class is used in implementation class using forward declaration:

@class ClusteringController;

then in one fuction it is used as:

- (long) filterImage:(NSString*) menuName
{   
    ClusteringController *cluster = [[ClusteringController alloc] init];
    [cluster showWindow:self];
    return 0;
}

When I build this project it produces the warning:

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

Also there is one more warning produced:

warning: no '-updateProxyWhenReconnect' method found

This warning is coming for the following line of code:

if(delegate) [delegate updateProxyWhenReconnect];

Can anybody help me to overcome these warnings?

+1  A: 

A forward declaration is used when the header file will be imported after the interface. It looks to me that you've used the @class directive after the interface for the class itself.

The normal use of a forward class declaration looks like this:

#import "SomeSuperClass.h"
@class Forwardclass;
@interface SomeClass : SomeSuperClass
{
    Forwardclass anIvar;
}
@property Forwardclass anIvar;

@end
#import "SomeClass.h"
#import "ForwardClass.h"
@implementation SomeClass
@synthesize anIvar;

-(void) setAnIvar:(ForwardClass *) aForwardClass;

@end

The @class directive is never used in an implementation (.m) file.

TechZen
I have done the changes told by you, but i have to make some changes in the method told by you which are as follows - Forwardclass anIvar; replaced by line Forwardclass *anIvar;@property Forwardclass anIvar; is replaced by @property(nonatomic, retain) Forwardclass *anIvar;After making these changes and changes told by you, when i tried to build the project the warning msg changed to warning: Mac OS X version 10.5 or later is needed for use of property
Shakti
Leopard is 10.5. You do have to be running 10.5 to get Objective-C 2.0 and properties.
TechZen
A: 

That's not what @class is for.

You use @class in the header file for another class, to tell the compiler that the class you're declaring does exist. Without it, the compiler would not know that that's a class name, and when you declare a variable as holding a pointer to an instance of that class, the compiler would think that you're just making up words. Using @class is called forward-declaring the class.

Your situation is different. You're in the implementation file for that class.

What the compiler needs from you now is the class's @interface. The warning is telling you that the compiler needs an @interface, but you haven't given it one (so, as far it knows, the @interface “may not exist”).

Normally, you would have written the @interface in a header file; how now to get it into the implementation file?

That's where the preprocessor comes in, with its #import directive. At the top of the implementation file (ClusteringController.m), import the header file:

#import "ClusteringController.h"

The preprocessor will replace this with the contents of that file, then hand the preprocessed code to the compiler, which will see the @interface there.

Peter Hosey
The #import "ClusteringController.h" line is already there in the implementation file.
Shakti
Shakti: Putting it at the end won't help. The `@interface` (which is to say, the `#import`) must be above the `@implementation`. You need to import that header, above the `@implementation`, in the implementation file for ClusteringController and for any classes that use it. Also, make sure you didn't somehow remove the `@interface` from the header by accident, and check for typos (declaring `@interface ClusteringController` and then referring to `ClustreingController` won't work).
Peter Hosey