哪些iOS类不支持将弱引用归零? [英] Which iOS classes that don't support zeroing weak references?
问题描述
在使用自动引用计数(ARC)时,在iOS中是否有无法使用 __ weak
指针引用的类的列表?
Apple的过渡到ARC发行说明只列出了到目前为止的Mac类:
支持调零弱引用?
您目前无法为以下类的实例创建归零弱引用:
NSATSTypesetter
,NSColorSpace
,NSFont
NSFontManager
,NSFontPanel
,NSImage
,NSMenuView
,NSParagraphStyle
,NSSimpleHorizontalTypesetter
,NSTableCellView
,NSTextView
,NSViewController
,NSWindow
和NSWindowController
。此外,在OS X中,AV Foundation框架中没有类支持弱引用。
有类似的UIKit类列表,甚至是
如果你试图形成对不支持弱引用的对象的弱引用,程序应立即死亡。这在 WWDC 2011 的 Objective-C Advancements in Depth 视频中提及。所以,你应该立即知道,如果你找到一个不支持他们的类。
我很确定在中转义到ARC发行说明表示所有 UIKit
类都是安全的。我不知道 AV Foundation
类的警告是否适用于iOS。我测试了在iOS 5和Lion上创建一个弱引用 AVCaptureSession
,但都没有崩溃。我测试了在Lion上创建一个对 NSWindow
的弱引用,并且用消息崩溃不能形成对类NSWindow的实例(0x102232ef0) code>。
Is there a list of classes in iOS that can't be referred with a __weak
pointer when using automatic reference counting (ARC)?
Apple's Transitioning to ARC Release Notes only lists Mac classes so far:
Which classes don’t support zeroing-weak references?
You cannot currently create zeroing-weak references to instances of the following classes:
NSATSTypesetter
,NSColorSpace
,NSFont
,NSFontManager
,NSFontPanel
,NSImage
,NSMenuView
,NSParagraphStyle
,NSSimpleHorizontalTypesetter
,NSTableCellView
,NSTextView
,NSViewController
,NSWindow
, andNSWindowController
. In addition, in OS X no classes in the AV Foundation framework support weak references.
Is there a similar list for UIKit classes or even iOS-specific classes in general?
Thanks.
If you try to form a weak reference to an object that doesn't support weak references, the program should die immediately. This is mentioned in the Objective-C Advancements in Depth video from WWDC 2011. So you should know immediately if you find a class that doesn't support them.
I'm pretty sure the lack of mention in Transitioning to ARC Release Notes means that all UIKit
classes are safe. I'm not sure if the warning about AV Foundation
classes applies to iOS or not. I tested creating a weak reference to AVCaptureSession
on both iOS 5 and Lion and neither crashed. I tested creating a weak reference to an NSWindow
on Lion and it crashed with the message cannot form weak reference to instance (0x102232ef0) of class NSWindow
.
这篇关于哪些iOS类不支持将弱引用归零?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!