Wanted: An Objective-C literal for a weak reference to self: @weakself.
| Originator: | jaredsinclair.rn | ||
| Number: | rdar://15854172 | Date Originated: | 18-Jan-2014 11:11 PM |
| Status: | Open | Resolved: | |
| Product: | iOS SDK | Product Version: | 7.0 |
| Classification: | Feature (New) | Reproducible: | Always |
Summary: It would be very helpful if there was an Objective-C literal for a weak reference to self: @weakself. Steps to Reproduce: It is very easy to introduce retain cycles and leaks in a modern, multi-threaded Objective-C application. The introduction of blocks and GCD have changed the way we program, yet it is still too easy to mistakenly leave strong references to `self` in a block, leading to a retain cycle and a leak One must remember to declare a __weak locally-scoped variable, usually named "weakSelf", before every block that needs to reference self. This gets tiresome after a while, even with a TextExpander snippet helping out. Not everyone uses the exact same nomenclature. Some use "weakSelf", others use "bSelf", and still others use "blockSafeSelf" if they're not into the whole brevity thing. Some developers use #defined macros to avoid having to declare a weak variable explicitly. The net result of all this difference is that our code is more tiresome to write and more difficult to read. Expected Results: If there was an Objective-C literal, perhaps @weakself, that could be used wherever one needs to reference self in a block, it would reduce boilerplate and increase the readability of shared code bases. Bonus points if @weakself gets the same Code Sense syntax highlighting as self.
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!