• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: "Tricks" of the "Trade"
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: "Tricks" of the "Trade"
      • From: jgo <email@hidden>
  • Prev by Date: Re: "Tricks" of the "Trade"
  • Next by Date: Re: "Tricks" of the "Trade"
  • Previous by thread: Re: "Tricks" of the "Trade"
  • Next by thread: Re: "Tricks" of the "Trade"
  • Index(es):
    • Date
    • Thread