Re: "Tricks" of the "Trade"
Re: "Tricks" of the "Trade"
- Subject: Re: "Tricks" of the "Trade"
- From: Enrique Zamudio <email@hidden>
- Date: Thu, 7 Jun 2001 02:05:28 -0500
On jueves, junio 7, 2001, at 01:55 AM, Max J Cantor wrote:
YES, i do agree with you, NSLog() is a wonderful tool. But, I have a
question, if you want to NSLog() to print the value of an int, is there a
better way than NSLog([[NSNumber numberWithInt:i] stringValue])?
NSLog(@"%d", i);
The first argument to NSLog must be a NSString, but it can take format
arguments similar to those of printf() and additionally it understands %@
which is used to print any NSObject or subclasses thereof.
int i;
unsigned u;
double f;
NSDictionary *dict;
NSLog(@"An integer %d unsigned %u double %f object %@", i, u, f, dict);
Sometimes our developers have been tearing their hair off because a NSLog
statement causes an app to crash... they sometimes use %@ to print an int
(this is bad because at runtime the int gets interpreted as a pointer to
an object but this is not the case and so the app crashes).
eZL