Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding NSLog syntax

(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];
like image 909
tahir Avatar asked Jun 25 '12 13:06

tahir


1 Answers

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.

like image 183
Ben Clayton Avatar answered Sep 22 '22 19:09

Ben Clayton