2013-02-16 66 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」取得了訣竅。