哪些 iOS 类不支持弱引用清零?
iOS 中是否存在使用自动引用计数 (ARC) 时无法通过 __weak 指针引用的类列表?
仅限 Apple 的过渡到 ARC 发行说明列出迄今为止的 Mac 类:
哪些类不支持弱引用清零?
您当前无法创建对以下类的实例的清零弱引用:
NSATSTypesetter
、NSColorSpace
、NSFont
、NSFontManager
、NSFontPanel
、NSImage
、NSMenuView
、NSParagraphStyle
、NSSimpleHorizontalTypesetter
、NSTableCellView
、NSTextView
、NSViewController
、NSWindow
和NSWindowController
。此外,在 OS X 中,AV Foundation 框架中的类不支持弱引用。
UIKit 类甚至 iOS 特定类是否有类似的列表?
谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您尝试对不支持弱引用的对象形成弱引用,则程序应该立即终止。 WWDC 2011 的Objective-C 深度进展视频中提到了这一点。因此,如果您发现一个不支持它们的类,您应该立即知道。
我非常确定 过渡到 ARC 发行说明 中没有提及意味着所有
UIKit
类都是安全的。我不确定有关 AV Foundation 类的警告是否适用于 iOS。我测试了在 iOS 5 和 Lion 上创建对 AVCaptureSession 的弱引用,并且都没有崩溃。我测试了在 Lion 上创建对NSWindow
的弱引用,它崩溃并显示消息无法形成对 NSWindow 类的实例 (0x102232ef0) 的弱引用
。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 aboutAV Foundation
classes applies to iOS or not. I tested creating a weak reference toAVCaptureSession
on both iOS 5 and Lion and neither crashed. I tested creating a weak reference to anNSWindow
on Lion and it crashed with the messagecannot form weak reference to instance (0x102232ef0) of class NSWindow
.