Which iOS classes that don't support zeroing w

2019-04-07 04:04发布

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, and NSWindowController. 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.

1条回答
兄弟一词,经得起流年.
2楼-- · 2019-04-07 04:14

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.

查看更多
登录 后发表回答