• 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: using printf to print objects
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: using printf to print objects


  • Subject: Re: using printf to print objects
  • From: Eric Ocean <email@hidden>
  • Date: Fri, 22 Oct 2004 11:30:06 -0700


On Oct 22, 2004, at 11:13 AM, Glenn Andreas wrote:

At 12:38 PM -0400 10/22/04, Gwynne wrote:
On Oct 22, 2004, at 12:30 PM, mail4 wrote:
I like NSLog, yet I find it too verbose.
Instead, something like

printf( "%s", [[someObject description] UTF8String] )

That hardly fixes the "verbose" problem.

Here's a simpler solution:

#import <Foundation/Foundation.h>

#define CFLog(format, ...) CFShow( [NSString stringWithFormat:format, ##__VA_ARGS__] )

int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

NSString *myString = @"Hello, World!";
CFLog( @"my log string with an object: %@", myString );

[pool release];
return 0;
}

The CFLog() macro should work with both format strings that take arguments and those that don't.

It doesn't print out the exact same information as NSLog; instead it print the CoreFoundation equivalent.
If anyone knows a way that NSLog could be cleanly formatted as a macro that returned a string for printf or an NSString for CFShow to use, that would be helpful.

Regards,

Eric Ocean

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden
  • Follow-Ups:
    • Re: using printf to print objects
      • From: "M. Uli Kusterer" <email@hidden>
References: 
 >using printf to print objects (From: mail4 <email@hidden>)
 >Re: using printf to print objects (From: Gwynne <email@hidden>)
 >Re: using printf to print objects (From: Glenn Andreas <email@hidden>)

  • Prev by Date: Re: using printf to print objects
  • Next by Date: Re: using printf to print objects
  • Previous by thread: Re: using printf to print objects
  • Next by thread: Re: using printf to print objects
  • Index(es):
    • Date
    • Thread