Functions
The NSLog routine is an example of a function that you have used in every program so far. Indeed, every program also has used a function called main. Let’s go back to the first program you wrote (Program 2.1), which displayed “Programming is fun.” at the terminal:
#import <Foundation/Foundation.h>int main (int argc, char * argv[]){ @autoreleasepool { NSLog (@"Programming is fun."); } return 0;}
This function, called printMessage, produces the same output:
void printMessage (void){ NSLog (@"Programming is fun.");}
The first line of a function definition tells the compiler four things about the function:
• Who can call it
• The type of value it returns
• Its name
• The number and type of arguments it takes
The first ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access