• 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
NS_FORMAT_FUNCTION for user defined functions
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NS_FORMAT_FUNCTION for user defined functions


  • Subject: NS_FORMAT_FUNCTION for user defined functions
  • From: Brandon Slack <email@hidden>
  • Date: Mon, 1 Nov 2010 15:37:16 -0400

Hey

I have my own logging methods as I want prepend a couple of things and
also have everything go to both console and a log file in debug mode.
I would also like the nice type checking that occurs when using NSLog
with clang. I noticed NSLog utilitizes __attribute__ format with
__NSString__ as the archetype and this appears to do what I want for
NSLog. I cannot however get this to work with my custom function:

Here is the code:
//void log_obj(NSString *format, ...) __attribute__ ((format
(__NSString__, 1, 2)));
void log_obj(NSString *format, ...) NS_FORMAT_FUNCTION(1,2);
void log_c(const char *format, ...) __attribute__ ((format (printf, 1, 2)));

void log_obj(NSString *format, ...) {
       va_list ap;
   va_start(ap, format);
       NSString *output = [[[NSString alloc] initWithFormat:format
arguments:ap] autorelease];
       va_end(ap);
       NSLog(@"%@", output);
}

void log_c(const char *format, ...)  {
       va_list ap;
   va_start(ap, format);
       vprintf(format, ap);
   va_end( ap );
}

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
#if __clang__
       NSLog(@"Clang");
#elif __GNUC__
       NSLog(@"GCC or close enough");
#endif

       NSLog(@"This causes a warning: %@");
       log_c("This also causes a warning: %s");
       log_obj(@"This should cause a warning, but does not: %@");
}

Am I missing something obvious? I am compiling with clang (and NSLog
works fine), as does the log_c function I wrote. Is there some hidden
setting?

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

This email sent to email@hidden

  • Prev by Date: Re: Xcode 3.2.4 - Mac OS X Reference Library missing
  • Next by Date: Over-release caused by Instruments?
  • Previous by thread: Re: Xcode 3.2.4 - Mac OS X Reference Library missing
  • Next by thread: Over-release caused by Instruments?
  • Index(es):
    • Date
    • Thread