1. Computing & Technology

Discuss in my forum

My First iPhone App

By , About.com Guide

9 of 9

Notes on Objective C

This tutorial has been about getting a simple first App up and running and one roadbump to gaining iPhone programming proficiency is the syntax of Objective-C. Even for experienced C/C++ developers it takes a bit of getting used to. So here's a look at some of the other language features used in this tutorial.

Dynamic Typing

Some declarations use the type id e.g.

-(IBAction)clickMe:(id)sender;

This is an example of dynamic typing. Instead of having to specify exactly which type is being passed in, you can just use id instead. It's actually a pointer to an object's data. It's a good idea to use static typing where possible as this makes code reliable but you are free to use id.

Naming conventions

the main one used is capitalize class names but have variables and methods start with lower case and use Camel case for longer names likeThis.

Creating Objects

Memory management is quite a complex topic and one which will be covered in the next iPhone Tutorial (as well as Views). A class is created by this type declaration.

MyObject * obj = [MyObject new]; // Note Obj-C 2.0

Prior to version 2.0 it needed an alloc, followed by an init. as in

MyObject * obj = [[MyObject alloc] init];

The example App used this older method to init the UIAlertView with the text for the popup.

Conclusion

This tutorial has been a fairly detailed introduction to the world of iPhone programming and Objective-C. In the next tutorial, I'll look at property in more detail, memory management and delve into views.

©2012 About.com. All rights reserved.

A part of The New York Times Company.