iPhone Apps: Objective C Development Pt. 1

xCode iPhone App DevelopmentHere I begin my tutorial on iPhone, iPod Touch and iPad development. It’s surprisingly easy to develop for these device’s if you have a background in programming.

You must learn a new language to be able to develop anything on these device’s and that is Objective C. In this tutorial I will begin by explaining Object Oriented Programming using Objective C.

I wrote and taped a tutorial on OOP using JavaScript. I go into a lot of detail and give a bunch of example’s that explain OOP. You might want to watch / read that before proceeding?

What is Object Oriented Programming? (Brief Explanation)

There are technically two types of modern programming languages.

Procedural Programmer’s write programs based on what actions they want the program to be able to do. Basically, they create one function after another, while thinking of the user of these function’s as some disembodied soul.

Object Oriented Programmer’s create a representation of every object that is needed to solve a problem and what action’s those object’s need to be able to perform. They create multiple blue prints for every object they will need and then based on that blue print they can build as many of those objects as they need.

The blueprint in OOP is known as the class definition. So if you are creating a blueprint for your average car you would have to create a car class definition.

Inside of your class definition you define the action’s your car needs to perform, called methods in OOP. You also need to define all the value’s you want to associate with your car, called variables in OOP. An example variable would be the color of your car, and an example method, would be drive forward.

After you define your class car you can now create individual cars, which are referred to as instances of type car in OOP.

What Make’s OOP More Powerful than Procedural

OOP always sound’s odd to long term procedural programmer’s, because they don’t normally grasp the power of what is called inheritance and polymorphism. I’ll explain them both now, using our car example.

All cars are similar, but they all have a special quality that sets them apart. Would you rather go off-roading in a jeep, or a Kia? Let’s use our drive forward method in an example. To implement a drive forward method in procedural programming, you have to start out by asking what type of car you are going to drive forward like this:

  • If the car is a Kia Soul
  • Your driving into a field
  • Then perform all of these action’s
  • If the car is a Hummer
  • Your driving into a field
  • Then perform all of these action’s
  • Repeat for every type of car

What is Inheritance?

When you create a new instance of type car with OOP, each car comes with the most common drive forward method. If your car doesn’t drive forward like a normal car, you just override that drive forward method.

This is the power of inheritance. Inherit those methods and variables you want and replace those that need to be different.

What is Polymorphism?

Let’s say you are going to test drive a new car that you’ve never heard of and is in the shape of a cube. You know it’s a car though, and decide to call it car. It drive’s forward and everything!

When you get behind the wheel, turn the key, and drive your car forward, you just experienced polymorphism. You where able to use it and everything just worked, even though you didn’t know it’s name. Much more on polymorphism later.

That is the basic’s of OOP. Now I’ll show you your first Objective C program.

Your First Objective C Program

Here I’ll show you a very simple Objective C program and then explain what it does step-by-step.

// Program that prints an addition of values on the screen

#import <Foundation/Foundation.h>

int main (int argc, const char * argv[])


NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init;

int numberOne = 1;

int numberTwo = 2;

int numberThree = numberOne + numberTwo;

NSLog (@”The sum of %i and %i equals %i”, numberOne, numberTwo, numberThree);

[pool drain];

return 0;


The first line in your program is a comment. Here you can comment on what the program does. Any word’s that are placed after two forward slashes are ignored all together. Also all the word’s that lie after a forward slash and a star (/*) are ignored until the comment ends with a (*/). Example:

/* All of these word’s are ignored */

The second line of code, #import <Foundation/Foundation.h> imports all of the information in the file named Foundation.h into your program. So, all of the variable’s and method’s created in Foundation.h, are now available for your use.

The next line of code: int main (in argc, const char * argv[]) is the definition of the function named main. Every Objective C program will contain a function named main and they all will look like this. This is what each word in this statement means:

int: The word int is telling the program interpreter that the function main will return a value of type integer, when it is done executing

main: The name of the function that is looked to first for direction, when a program is first executed.

(): Everything passed to the function main, will lie between these two braces. The variable’s inside of these braces are called arguments.

int argc: int here states that the value of argc, is of type integer. The variable argc, contains the number of arguments that are being passed to the function main. If that doesn’t make sense don’t worry about it now.

char *argv[]: char tells us that this variable is of type character, meaning it will contain a string of letters, numbers and symbols. The brackets [], tell us that argv is an array. An array is like a bunch of boxes inside of a bigger box, that each contain different values. More on arrays soon.

The braces {} surround every action that will be performed by the function main(). When the interpreter sees the closing brace }, it knows that the function has ended.

The line of code:

NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init;

Reserves space in the computers memory, for use to use for our program. It provide’s the resources needed for our program to execute properly. More on it later as well.

Special Note: Every statement is ended in Objective C with a semi-colon. (;)

These line’s of code:

int numberOne = 1;

int numberTwo = 2;

int numberThree = numberOne + numberTwo;

Define 3 variables that are all of type integer, and then assign them a value. The first 2 are assigned a value using the equals sign, followed by the value to assign.

The third line of code assign’s a value to the variable numberThree, by adding the value’s of the two previous variable’s together and then assigning that sum to numberThree.

Special Note: Variable’s in Objective C are case sensitive, meaning that numTwo is not the same variable as NumTWO.

The code:

NSLog (@”The sum of %i and %i equals %i”, numberOne, numberTwo, numberThree);

NSLog is a function that was created and is stored in Foundation.h. Whatever value’s that are passed to it will be displayed on the screen, of whoever executes this program.

Every thing placed between @” and “, will be displayed. If you want to show variable value’s in this string of text, you tell the interpreter where those variable value’s will show up with the symbol %i. The values will appear based off of the order they are in after the quote “.

[pool drain];

Tells the computer that you know longer need the memory it provided to you. More on this later as well.

return 0;

This final line tells the interpreter to stop executing code in the function main. The 0 tells the interpreter, that the program ended because it wanted to and not because of an error.

Like I stated previously the closing curly brace signify’s the end of the function main. This is what the user would see on their screen, if they executed this program:

The sum of 1 and 2 equals 3

That’s All Folk’s

I covered many things in this tutorial. The basic’s of OOP. Don’t worry, the next article will cover a lot more on OOP. You also saw your first Objective C program. I know it looks a little weird, but in no time you’ll be cranking out programs of your own.

Here to Serve

Think Tank

8 Responses to “iPhone Apps: Objective C Development Pt. 1”

  1. Malcolm says:

    Great Tutorial

  2. Does your website have a contact page? I’m having trouble locating it but, I’d like to send you an email.
    I’ve got some ideas for your blog you might be interested in hearing. Either way, great site and I look forward to seeing it develop over time.

  3. leonardo says:

    I have been going through few tutorials of yours and they are really awesome.
    I have been looking for Objective C and iphone tutorials which you said it will be out soon.If they are already out there please post me a link. 🙂

    • Derek Banas says:

      Thank you 🙂 I had to take down my iPhone app because I made one that was to similar to a popular game. I’ll remake the tutorials after I’m done making Android apps. Sorry about that

  4. Hey outstanding blog! Does running a blog like this take a great deal of work?
    I’ve no knowledge of coding however I had been hoping to start my own blog soon. Anyhow, should you have any recommendations or tips for new blog owners please share. I know this is off subject however I simply wanted to ask. Many thanks!

    • Derek Banas says:

      Thank you very much 🙂 This is basically my only hobby. I spend about 2 hours a day making videos and writing articles.

      I have found that if I keep the content fresh and interesting to me that I have no problem pushing out a ton of content. I only get bogged down if I cover the same topic for to long. I also tend to constantly try to out due my last tutorial which can make it hard, but I enjoy that.

      I cover exactly how I make videos here How I Make YouTube Videos. I show how the super successful YouTubers (Not Me) make videos here How to Video Blog.

      I hope that helps. I consider myself to be more of a vlogger then a blogger, but I’ve played both roles.


  1. Tweets that mention iPhone Apps: Objective C Development Pt. 1 | New Think Tank -- Topsy.com - [...] This post was mentioned on Twitter by UK iPhone Developers and Mobile App Dev Jobs, Derek Banas. Derek Banas…

Leave a Reply

Your email address will not be published.