Re: NSLog() what is it?
Re: NSLog() what is it?
- Subject: Re: NSLog() what is it?
- From: email@hidden
- Date: Sat, 22 Jun 2002 07:03:42 -0500
Welcome aboard!
NSLog() is a function call.. and VERY handy..
I am not sure where the doc for it resides.. :-)
Anyway, here is a short "man page" on it..
NSLog( NSString *format, arg1, ... )
NSLog() takes as its first argument a format string with the format
being the same as in man 3 printf ..
It then resolves the format string and arguments into a nice displayable
text and dumps it out to "standard output"
(the Unix standard out file handle.. although come to thing on it it MAY
be standard error.. either way,
it shows it to you somehow.. using PB it is shown in the run screen..
Most people use it to show "interesting" things that are going on in
their application (ok ok.. debug info
mostly! LOL)
The important thing is that the first argument must be a NSString.. and
then you pass one or more
addition arguments that match any format specifiers in the NSString..
The VERY useful format specifier of %@ means "class" and will expand to
whatever it appropriate
for the class (i.e. whatever the class maybe have overridden in the
"display" method (i think)..
Examples
--------------
NSLog(@"Hello world") ; // Have to have this as the first right??
- Display Hello world
NSLog(@"User's name running this app is: %@", NSUser() ) ;
NSLog(@"Value of my interesting class is: %@", myClassInstance ) ;
In your case below the only problem was that y ou did not need NSLog() a
NSString as the
first argument..
Cheers
On Saturday, June 22, 2002, at 01:55 AM, Michael Zornek wrote:
Hi everyone! First post to the list!
I'm in ch 6 of Learning Cocoa (where we are building Cocoa Foundation
Tools)
and it tells me to use NSLog all over the place but when I went to
option
click it for documentation it wasn't there. After some more directed
searching I couldn't find it ether.
My main is below, and here are my questions:
1) Is NSLog() an object? If so, why does option clicking it not return
information?
2) Where is info. In particular the book tells us to use the following
line
to get the value inside of an array:
NSLog(@"Array desctiption: %@ items.\n", myArray);
But when I try to out my "itemcount" in a similar fashion:
NSLog(@itemcount);
-or-
NSLog(itemCount);
It get errors :-(
I think in general I'm looking to replicate something similar to this
C++
code that I've been writing.
cout << "The number of items in my array are: " << itemCount << endl;
thanks in adv. for all your help,
~ Mike, a lowely web guy working his way into platform coding.
My main:
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[]) {
// init
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSMutableArray *myArray;
NSString *myString;
int itemCount;
// start code
NSLog(@"Hello, World!");
myArray = [[NSMutableArray alloc] init];
NSLog(@"Array desctiption: %@ items.\n", myArray);
[myArray addObject: @"Here's a string!"];
[myArray addObject: @"Here's a another string!"];
NSLog(@"Array desctiption: %@ items.\n", myArray);
itemCount = [myArray count];
// NSLog(@itemcount);
// NSLog(itemCount);
[myArray release];
[pool release];
return 0;
}
--
Mike Zornek | Project Leader
Apple Student Developers
The Insanely Great Site with the Insanely Long URL
http://www.applestudentdevelopers.org
Personal Site:
http://www.mikezornek.com
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.