2012-02-08 49 views
18

我有一個看起來像這樣的屬性:爲代表弱財產

@property (weak, nonatomic) id<NavigationControllerDelegate> delegate; 

但是當我運行我的應用程序,我得到以下錯誤:

objc[4251]: cannot form weak reference to instance (0x101e0d4b0) of class TabBarController 

唯一的原因,我能從谷歌得到這個錯誤是,當你嘗試對覆蓋retain/release/dealloc的對象形成一個弱引用時,你會得到它,而我並不這樣做。我的TabBarController繼承自NSViewController。

任何人都知道可能會導致這種情況?它適用於如果我使用「分配」,但顯然我寧願使用「弱」。

+0

CocoaFu, 「不能形成弱引用實例......」 是總是出現運行時錯誤。 – 2012-02-08 12:56:52

回答

36

根據蘋果的Transitioning to ARC Release Notes

You cannot currently create weak references to instances of the following classes:

NSATSTypesetter , NSColorSpace , NSFont , NSMenuView , NSParagraphStyle , NSSimpleHorizontalTypesetter , and NSTextView .

Note: In addition, in OS X v10.7, you cannot create weak references to instances of NSFontManager , NSFontPanel , NSImage , NSTableCellView , NSViewController, NSWindow , and NSWindowController . In addition, in OS X v10.7 no classes in the AV Foundation framework support weak references.

(注:一個需要非常小心nonzeroing弱引用...)

+0

好東西!根據我以前的發現,我懷疑NSViewController有些不同。我沒有看到你剛纔粘貼的東西。謝謝,這明確說明了整個事情! – 2012-02-08 13:47:19