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 ...

Get Programming in Objective-C, Sixth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.