How to create your own Data Type using typedef

With typedef you can specify custom variable types. Instead of having a variable such as int, you could create your own – such as yourInt:

Now you have your own variable type called youInt which behaves just like an int.

The power of typedef becomes clearer when combined with enumerations we were discussing previously. You can create your own data type of enum, creating and addressing your values more easily. Let’s stick with the drink size example from earlier:

Xcode will code complete all available values, making your life a bit easier when coding.

Many of Apple’s pre-defined super long complex types are created this way. Think of all those NSDateFormatter values you can use, such as NSDateFormatterStyleLongStyle.

Jay is the CEO and founder of WP Hosting, a boutique style managed WordPress hosting and support service. He has been working with Plesk since version 9 and is a qualified Parallels Automation Professional. In his spare time he likes to develop iOS apps and WordPress plugins, or draw on tablet devices. He blogs about his coding journey at and

Add your voice!