Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which iOS classes that don't support zeroing weak references?

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.

like image 398
adib Avatar asked Feb 05 '12 02:02

adib


1 Answers

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.

like image 158
rob mayoff Avatar answered Oct 05 '22 04:10

rob mayoff