Computer Music: Musc216
Cocoa Sample Code


NSLog

NSLog allows you to print messanges and values to the 'Console" (the Run Log). It is similar to:

printf()

It takes a format string and a comma-separated list of variables to be substituted into the format string. When displaying the string, NSLog prefixes the generated string with the name of the application and a time stamp.

Here is a list of all the tokens recognized by NSLog:

Symbol Displays
%@ id
%d, %D, %i long
%u, %U unsigned long
%hi short
%hu unsigned short
%qi long long
%qu unsigned long long
%x, %X unsigned long printed as hexidecimal
%o, %O unsigned long printed as octal
%f, %e, %E, %g, %G double
%c unsigned char as ASCII character
%s char * (a null-terminated C string of ASCII characters)
%S unichar * (a null-terminated C string of Unicode characters)
%p void * (an address printed in hexidecimal with a leading 0x
% % A % character
   
@"Any text you want" prints some message you define

Examples:

Printing the value of a slider using NSLog:

- (IBAction)setMetTempo:(id)sender
{

   myValue = [sender intValue];
   myOtherValue = myValue*2;

   if (myOtherValue< 20) {
       myOtherValue = 20;
   }

   NSLog(@"My message, myOtherValue = %d", myOtherValue);

   [myField setIntValue:myOtherValue];

}

 

Main Page