The Objective-C programming language provides a keyword called typedef, which you can use to give a type a new name.
Following is an example to define a term BYTE for one-byte numbers:
typedef unsigned char BYTE;
Also you can use lowercase, as follows:
typedef unsigned char byte;
After this type definition, the identifier BYTE can be used as an abbreviation for the type unsigned char, for example:
BYTE b1, b2;
You can use typedef to give a name to user-defined data type as well.
typedef vs #define
The #define is a Objective-C directive, which is also used to define the aliases for various data types similar to typedef but with following differences:
- The typedef is limited to giving symbolic names to types only.
- The typedef interpretation is performed by the compiler
- #define can be used to define alias for values as well, like you can define 1 as ONE, etc.
- #define statements are processed by the pre-processor.