The typedef Statement

Objective-C provides a capability that enables the programmer to assign an alternative name to a data type. This is done with a statement known as typedef. The following statement defines the name Counter to be equivalent to the Objective-C data type int:

typedef int Counter;

You can subsequently declare variables to be of type Counter, as in the following statement:

Counter  j, n;

The Objective-C compiler treats the declaration of the variables j and n, shown previously, as normal integer variables. The main advantage of the use of the typedef in this case is in the added readability it lends to the definition of the variables. The definition of j and n makes clear the intended purpose of these variables in the program. ...

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.