NSObject Needs a *NickName* Property (Only is used in Debug mode)
| Originator: | kdbdallas | ||
| Number: | rdar://14687825 | Date Originated: | 2013-08-08 |
| Status: | Open | Resolved: | |
| Product: | iOS SDK | Product Version: | All (7.0) |
| Classification: | Enhancement | Reproducible: | N/A |
Summary:
NSObject needs something like a "name" or "nickname" property so while debugging you can quickly and easily see which object of type *whatever* that is being, say, passed into a method.
So you can quickly look at the debugger and know which, say, UITableView was passed in.
For example a class that is the Data Source of 2 tables.
Breakpoint in say, numberOfRowsInSection, and easily know which table it is.
You can use memory addresses (dirty and have to lookup each one) or tags but then its, "ok this is tag 5, now what was 5 again... *search*"
Instead you see: NickName = DingleBeary and know what one you are working with.
This property could be skipped in Release builds as to reduce memory and such.
Steps to Reproduce:
*Just one example of many*
Create 2 different UITableViews, create a class that is the DataSource of both tables.
Place a breakpoint in:
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
You dont easily know which TableView you are using.
Add a tag when creating table and then at this point you have to lookup which object was which tag.
Compare memory addresses: dirty and takes time
Look at other properties: Unreliable
Use a Category: You have to create a category for everything as creating a category on NSObject wont be used if you create an internal object.
Look at description: Objects like UITableView don't have descriptions that help:
<UITableView: 0x14100e00; frame = (0 0; 0 0); clipsToBounds = YES; gestureRecognizers = <NSArray: 0x11e43c50>; layer = <CALayer: 0x11e59390>; contentOffset: {0, 0}>
Expected Results:
You should be able to quickly and easily see what object you are looking at.
Yes you would have to assign that NickName value when creating the object, but it would save SO much time in debugging
Actual Results:
You can't QUICKLY and EASILY what objects are what for internal objects such as UITableView
Regression:
Notes:
Should be the same in AppKit
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!
Good idea. Until (if ever) Apple adds this, you can do it yourself with objc_setAssociated, as described here: http://stackoverflow.com/questions/16019782/any-gotchas-with-objc-setassociatedobject-and-objc-getassociatedobject