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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With