Typedef in Objective C?

The typedef keyword lets you create new data types or redefine existing ones. After typedef’ing an unsigned char in the following example, we can use ColorComponent just like we would use char, int, double, or any other built-in type:

// main.m
#import <Foundation/Foundation.h>

typedef unsigned char ColorComponent;

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        ColorComponent red = 255;
        ColorComponent green = 160;
        ColorComponent blue = 0;
        NSLog(@"Your paint job is (R: %hhu, G: %hhu, B: %hhu)",
              red, green, blue);
    return 0;

One thought on “Typedef in Objective C?

  1. You post very interesting content here. Your page deserves much bigger audience.
    It can go viral if you give it initial boost, i know very useful service that can help
    you, just type in google: svetsern traffic tips

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s