objective-c - Cocoa:构建警告,转发声明的类和 @interface 可能不存在

标签 objective-c cocoa forward-declaration

我正在尝试在 Leopard 下的项目中构建集群插件。我有以下两个问题。

在项目中接口(interface)类定义为

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

该类在实现类中使用前向声明:

@class ClusteringController;

然后在一个函数中它被用作:

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

当我构建这个项目时,它会产生警告:

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

此外还产生了一个警告:

warning: no '-updateProxyWhenReconnect' method found

以下代码行会出现此警告:

if(delegate) [delegate updateProxyWhenReconnect];

有人可以帮助我克服这些警告吗?

最佳答案

当头文件将在接口(interface)之后导入时,将使用前向声明。在我看来,您在类本身的接口(interface)之后使用了 @class 指令。

前向类声明的正常使用如下所示:

#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

@class 指令从未在实现 (.m) 文件中使用。

关于objective-c - Cocoa:构建警告,转发声明的类和 @interface 可能不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2386676/

相关文章:

iphone - ViewController 从生命周期开始到结束(不使用 NIB 和使用 NIB)的生命周期函数的完整列表?

c++ - 在头文件中声明 Qt 类

ios - 添加覆盖几个连续 UITableViewCells 的 UIButton

ios - 日期类型的dateFormatter字符串2013-03-24T02:15:23-08:00 + objective-c

objective-c - 如何创建后台运行的 Cocoa 应用程序?

c++ - 如何解决 Boost::BGL 模板<->类循环依赖?

c++ - 试图解决我的双端队列类和树类之间的循环引用错误

objective-c - 使用 stringByAppendingString 将字符添加到 Xcode/objective-C 中的现有字符串

ios - 将坐标从十进制度数转换为可能的 EPSG 4326

objective-c - Reeder Mac 应用程序在切换文件夹时如何以动画方式显示列表?