gpt4 book ai didi

objective-c - 哪些 iOS 类不支持归零弱引用?

转载 作者:可可西里 更新时间:2023-11-01 03:31:57 24 4
gpt4 key购买 nike

在使用自动引用计数 (ARC) 时,iOS 中是否存在不能使用 __weak 指针引用的类列表?

Apple 的 Transitioning to ARC Release Notes目前只列出 Mac 类:

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, and NSWindowController. In addition, in OS X no classes in the AV Foundation framework support weak references.

UIKit 类或一般的 iOS 特定类是否有类似的列表?

谢谢。

最佳答案

如果你试图对一个不支持弱引用的对象形成一个弱引用,程序应该立即死掉。这在来自 WWDC 2011Objective-C 深入推进 视频中提到。 .因此,如果您发现不支持它们的类,您应该立即知道。

我很确定Transitioning to ARC Release Notes 中没有提及意味着所有 UIKit 类都是安全的。我不确定有关 AV Foundation 类的警告是否适用于 iOS。我测试了在 iOS 5 和 Lion 上创建对 AVCaptureSession 的弱引用,但都没有崩溃。我测试了在 Lion 上创建对 NSWindow 的弱引用,它崩溃并显示消息 cannot form weak reference to instance (0x102232ef0) of class NSWindow

关于objective-c - 哪些 iOS 类不支持归零弱引用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9146540/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com