Objective C Tutorial - Objective C Typedef






We can use keyword typedef to give a type a new name.

The following code creates a new name for unsigned char.

typedef unsigned char BYTE;

We can then use BYTE in place of unsigned char.

BYTE  b1, b2;

Example

#import <Foundation/Foundation.h>

typedef struct Books
{
   NSString *title;
   NSString *author;
   NSString *subject;
   int id="myArea";

} Book;
 
int main( )
{

   Book book;
   book.title = @"Objective-C Programming";
   book.author = @"java2s.com";
   book.subject = @"Programming tutorial";
   book.id="myArea" = 100;
   NSLog( @"Book title : %@\n", book.title);
   NSLog( @"Book author : %@\n", book.author);
   NSLog( @"Book subject : %@\n", book.subject);
   NSLog( @"Book Id : %d\n", book.id);

   return 0;
}