Re: NSLog() what is it?
Re: NSLog() what is it?
- Subject: Re: NSLog() what is it?
- From: Brent Gulanowski <email@hidden>
- Date: Sat, 22 Jun 2002 08:29:36 -0400
NSLog is a normal C function that works like printf(), but is nicer and
supports Obj-C objects. You have to send it an NSString * plus a number of
format specifiers like *printf(). If you look at the NSString docs, you'll
see some relevant methods that will give you a hint as to what's going on
behind the scenes.
When you do @"blah" you're instantiating a static NSString. NSLog submits
that to stringWithFormat:args: to make a formatted string, and then I
believe converts that to a C string before calling printf. I don't know of
any equivalent to C++'s stdin/stdout (or i/o streams of any kind) in Cocoa.
May I suggest you acquire Aaron Hillegass's Cocoa Programming for Mac OS X?
Learning Cocoa has a bad rep (never read it myself). Also check out the
foundation functions on Apple's page (find link on the Cocoa docs page or
the Foundation classes page).
Brent
On Saturday, June 22, 2002, at 02: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.
--
Brought to you by Mail on Mac OS X. Think Different.
_______________________________________________
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.