This is so useful, the AS3 equivalent would be toString().
Not enough developers take advantage of it in the as3 world either, but if you’re learning iphone development you should start off correctly whether coming from as3 or not.
- (NSString *)description;
Don’t place that in your header as you are overwriting this method. So in essence it’s already in your header file.
In your implementation file have something like this:
- (NSString *)description { // This really goes in one line, but to prevent scrollbars here, its 3 return [NSString stringWithFormat: @"My velocity X,Y is %f,%f and health is %i", self._vx, self._vy, self._health]; }
You call it in any other class using:
NSLog(@"Created new letter: %@", newLetter);
I find that so much more useful that constantly creating new NSStrings for logs.
Then i get annoyed of seeing them scattered around, so I remove all the commented out ones.
This way, it’s no sweat and more useful cus you can take the time to make it nice, once.
Tags: Uncategorized