Understanding NSLog syntax
Solution 1
I agree this is pretty confusing when you're starting out. The main reason is that the NSLog method, like many others in Core Foundation, is a C-based API, rather than an Objective-C API. C-style functions look like this myFunction(myParameter1, myParameter2).
All the GUI stuff you're probably used to [UIView presentModalViewController:] etc is based around an Objective-C API, with the square brackets that you've seen for functions (called selectors in Obj-C) . The Objective-C language sits on top of C, so you will find both styles in most apps.
Solution 2
As I understand it, NSLog isn't an Objective C function but a C function built into the foundation of Cocoa. Therefore it conforms to basic C functions with variadic arguments.
Solution 3
NSLog
may seem like a class, but it isn't.
NSLog
is aFoundationKit
function for printing debug statements to the console. It is defined inNSObjCRuntime.h
:
void NSLog(NSString format, ...);
There is a good amount of information here: http://cocoadev.com/wiki/NSLog
EDIT: As @fyngyrz pointed out, the page is dead. So here is a wayback-machine version of the page from 2012
tahir
Updated on September 20, 2020Comments
-
tahir almost 4 years
(I'm a cocoa beginner and ) I'm wondering why we should do:
NSLog(@"this is the variable value: %d",variable);
and not something like this:
[NSLog outputThis:@"this is the variable value: %d" param:variable];
-
onmyway133 almost 10 yearsApple decides everything, and we 'll like it
-
fyngyrz almost 7 yearsNo, there isn't. The page is gone.
-
Alladinian almost 7 years@fyngyrz Thanx. Edited the answer.
-
Pranav Kasetti over 3 years^ is the story of every iOS developer XD