2013-02-16 67 views
1

OK,这是我的情况...实例方法 - 为App委托财产

我的应用程序委托声明如下:

@interface AppDelegate : NSObject <NSApplicationDelegate> 

@property (assign) IBOutlet NSWindow *window; 
@property (assign) ppDocumentManager* documentManager; 

现在,从不同的位置我米试图访问documentManager,像这样:

AppDelegate* de = (AppDelegate*)[[NSApplication sharedApplication] delegate]; 
ppDocumentManager* docs = [de documentManager]; 

,并在文件的顶部,我还添加了@class AppDelegate;,以便编译器知道AppDelegate代表什么。

它工作正常。


然而,我不断收到警告:

Instance method '-documentManager' not found (return type defaults to 'id') 

我应该以消除所有的警告呢?

回答

2

OK,这是对我工作:

  • 我已决定在.m文件利用的documentManager的使用开始@class AppDelegate;,为了避免循环引用的风险。

然而,事实证明,这是没有必要的。

我刚刚进口AppDelegate.h,一切都到位。

Pheww ....

+0

您将不会导入.m文件,因此没有循环导入的风险。另外,@class不会告诉编译器该类的方法和属性。 – 2013-02-16 13:48:48

+0

@FirozeLafeer的确如此。 :-) – 2013-02-16 14:10:08

0

我有同样的问题,我发现它有一个名为“AppDelegate中的”的appdelegate而不是一些自定义的名称,比如“MyAppDelegate”来了。

将我的类重命名为“MyAppDelegate”,导入为“MyAppDelegate.h”取得了诀窍。