FROM : Piers Uso Walter
DATE : Fri Aug 11 18:41:32 2006
Am 11. Aug 2006 um 18:19 schrieb Dirk Stegemann:
> Hi,
>
> Am 11.08.2006 um 19:08 schrieb Roland Silver:
>> The trouble with NSLog is that it prints all that extra stuff
>> before the actual formatted message. For example,
>> NSLog(@"sender=%@\n", sender);
>> logs this:
>> 2006-08-11 10:06:29.545 EmulatorV4.17.04[1380] sender=<MenuItem:
>> 0x449040 Ad Hoc Test>
>> in the Run log, rather than just:
>> sender=<MenuItem: 0x449040 Ad Hoc Test>
It's easy to write such a function.
Something like this should do. [not tested beyond compilability and
the primitive test case in main()]
#import <Foundation/Foundation.h>
int printWithAtFormat(NSString *aFormatString, ...)
/*" Raises an NSInvalidArgumentException if aFormatString is nil. "*/
{
va_list myArgs;
NSString *outputString;
va_start(myArgs, aFormatString);
outputString = [[NSString alloc] initWithFormat:aFormatString
arguments:myArgs];
va_end(myArgs);
int retval = printf("%s", [outputString lossyCString]);
[outputString release];
return retval;
}
int main(int argc, const char *argv[])
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSArray *array = [NSArray arrayWithObjects:@"A", @"B", nil];
printf("printf: array = %s [%d elements]\n", [[array
description] lossyCString], [array count]);
printWithAtFormat(@"printWithAtFormat: array = %@ [%d elements]\n",
array, [array count]);
[pool release];
return 0;
}
With kind regards
Piers
--
Piers Uso Walter <Piers.<email_removed>>
ilink Kommunikationssysteme GmbH
DATE : Fri Aug 11 18:41:32 2006
Am 11. Aug 2006 um 18:19 schrieb Dirk Stegemann:
> Hi,
>
> Am 11.08.2006 um 19:08 schrieb Roland Silver:
>> The trouble with NSLog is that it prints all that extra stuff
>> before the actual formatted message. For example,
>> NSLog(@"sender=%@\n", sender);
>> logs this:
>> 2006-08-11 10:06:29.545 EmulatorV4.17.04[1380] sender=<MenuItem:
>> 0x449040 Ad Hoc Test>
>> in the Run log, rather than just:
>> sender=<MenuItem: 0x449040 Ad Hoc Test>
It's easy to write such a function.
Something like this should do. [not tested beyond compilability and
the primitive test case in main()]
#import <Foundation/Foundation.h>
int printWithAtFormat(NSString *aFormatString, ...)
/*" Raises an NSInvalidArgumentException if aFormatString is nil. "*/
{
va_list myArgs;
NSString *outputString;
va_start(myArgs, aFormatString);
outputString = [[NSString alloc] initWithFormat:aFormatString
arguments:myArgs];
va_end(myArgs);
int retval = printf("%s", [outputString lossyCString]);
[outputString release];
return retval;
}
int main(int argc, const char *argv[])
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSArray *array = [NSArray arrayWithObjects:@"A", @"B", nil];
printf("printf: array = %s [%d elements]\n", [[array
description] lossyCString], [array count]);
printWithAtFormat(@"printWithAtFormat: array = %@ [%d elements]\n",
array, [array count]);
[pool release];
return 0;
}
With kind regards
Piers
--
Piers Uso Walter <Piers.<email_removed>>
ilink Kommunikationssysteme GmbH
| Related mails | Author | Date |
|---|---|---|
| Roland Silver | Aug 11, 17:55 | |
| Dirk Stegemann | Aug 11, 17:57 | |
| Roland Silver | Aug 11, 18:08 | |
| Dirk Stegemann | Aug 11, 18:19 | |
| Roland Silver | Aug 11, 18:26 | |
| Piers Uso Walter | Aug 11, 18:41 | |
| Joseph Kelly | Aug 11, 18:41 | |
| Dirk Stegemann | Aug 11, 18:47 | |
| Deborah Goldsmith | Aug 11, 23:41 | |
| Andrew Farmer | Aug 12, 00:28 | |
| Wayne Hasley | Aug 12, 01:28 |






Cocoa mail archive

