Reputation: 1
How can I print name of objects in Xcode? I am getting address of objects. Instead, I want names. Output is coming the address of boxes instead. How to get name of the boxes box 1 box 2?
Upvotes: 0
Views: 302
Reputation: 318824
You can't. Each Box
instance has no concept of the name of the variable used elsewhere to point to it. In fact, any number of different variables can reference the same Box
instance so it makes no sense to attempt to print the variable name.
If you really want a name, add a name
property to your Box
class.
And the best way to get sane output when logging a class instance, override the description
method.
Add this to your Box
class in the .m file:
- (NSString *)description {
return [NSString stringWithFormat:@"Box: h:%f x w:%f x l:%f", _height, _width, _length];
}
Upvotes: 1