How To Make iPhone Apps – Object Oriented Programming and Classes

Welcome to my series on How To Make iPhone Apps with no programming experience – where we’ll turn even the non-programmer into an iOS developer! Here’s the article index for the entire series in case you missed it.
In this article, we’re going through some basic but core programming principles that you’ll need to build iPhone apps.
If you’re coming from another programming language, then chances are you could probably advance to the next article. Otherwise don’t worry, read on and welcome to the wonderful world of programming!

1. Object Oriented Programming

The common understanding that non-technical people have about programming and coding is that it’s a series of commands and statements that tell the computer what to do. (At least, for the sample of people that I’ve asked!)

I never try to explain anymore than that because the explanation above works for them and that’s what they understand. That’s cool.

But if we’re about to build iPhone and iPad applications, I’m afraid that we’re going to have to get a little deeper than that!

The programming language we use to build iPhone and iPad apps is called Objective-C and it’s also a form of object oriented programming.

I’m going to borrow from Wikipedia here:

An object-oriented program may be viewed as a collection of interacting objects… In OOP, each object is capable of receiving messages, processing data, and sending messages to other objects. Each object can be viewed as an independent “machine” with a distinct role or responsibility.

Basically, the Wikipedia quote is saying that our program, or app, is just a bunch of objects interacting with each other.

Each object is defined by a “blueprint” which describes the characteristics of that object. But the blueprint merely describes the object.

In order to have an object with which we can use to perform tasks, we have to create an “instance” of it using the blueprint.

Think of the blueprint as a plastic mould. By filling the mould with plastic and allowing it to cool, we can manufacture an instance of an object.

When we’re building our iOS app, we’re essentially defining a series of blueprints for our objects, telling the program to create instances of objects and then issuing commands and statements for the objects to perform tasks and interact with other objects.

Got it? I know you got it.


2. So What Is A Class?

You already know what this is.

It’s just the correct term for the “blueprint” that we’ve been talking about! So from now on, I’m going to say “class” instead.

In Objective-C, a class is defined with two files; a “.h” file and a “.m” file. There are various names for these two files, but we’ll stick with what Apple uses in their documentation. The .h file is called the “header” file while the .m file is called the “source” file.

So for example, if I were intending to write a class for a Superhero, I would have Superhero.h and Superhero.m.

The header file is where we tell other classes that interact with our class exactly what sort of interaction is available. You can think of the header file as a sort of public description of the class.

In Superhero.h (the header file), I would state what sorts of variables, properties and methods are available for other objects to interact with my Superhero. (More on variables, properties and methods farther down).

The source file however is where you implement the “guts” of the Class. This is where all of the code and logic of your Class goes.

In Superhero.m (the source file), I would write the code for what happens if another object actually called upon the variables, properties and methods that I defined in Superhero.h (the header file).

I want to remind you that the header file and source file, together, define a class and that a class is simply a “mould” or a “blueprint”. In our programming later on, we’ll be able to create instances of our class which we call objects. And we’ll make these objects interact with each other.

A few paragraphs ago, I mentioned that we use the Header file to specify what sorts of interactions our class would permit. I hinted at variables, methods and properties, so let’s take a closer look at what those are!

3. Variables To Store Things

You can think of a variable as a bucket to store a value of some sort. Once you declare a variable, you can set its value and retrieve it later on when you need it.

However, you must define the type of value that a variable can store and it can only store values of that type. You can even specify other classes as the type that you’d like to store!

Variables are essential to our programming because we’ll need to keep track of different objects, values and other data. We will keep track of this stuff by declaring variables of the correct type and we’ll use variables to help us keep track of these objects, values and data.

When we declare a variable in a class, your intention is probably to store some data that is related to that class.

In our Superhero.h file, we might declare a variable to identify and store our Superhero’s intelligence, stamina etc. Or we might even declare a variable with a type Superhero, in order to refer to our Superhero’s superpal!

What type of variables are there?
There are two broad categories of variables: value types and reference types. Then there are a whole bunch of variable types that fall into one of these two categories. Any variable which keeps track of objects is a reference type and the other ones are value types.

The good news is that this variable type terminology doesn’t vary too much from language to language (in terms of programming languages).

The bad news is that if this is the first time you’re seeing this, the variable type names won’t seem very intuitive to you!

Here are some of the common ones you’ll be using:

With this variable type, you’ll be storing string data. In other words text! In most programming languages, text is thought of as a “string of text”, thus the variable type “string”. In Objective-C, it’s “NSString”. The extra “NS” is just something that Apple denotes their own classes with, so you’ll be seeing it again and again with other Apple classes. 

NSString is an Apple class, so remember that instances of classes are objects and variables that keep track of objects are reference-type variables. Later on, you’ll see that when we declare reference type variables, we’ll denote it with an additional asterisk (*) that we don’t have with value type variables.

“int” stands for integers. Did I just bring back memories from high school Math? 🙂
With this variable type, we store whole numbers. This is a value type variable.
“BOOL” stands for boolean and this variable type can have only one of two possible values. “YES” or “NO”.
You can also assign it “TRUE” or “FALSE” or “1” and “0” but it means the same thing. 

You might be thinking, couldn’t we just represent this with a string or int type variable? You’re right, but if you know that the data you’re storing could only be one of two values, then by using a BOOL you would save memory and make your code less error-prone.

This is a value type variable.

With this variable type, we store decimal numbers. 

This is a value type variable.

I mentioned above that you can specify a class name as a variable type. When you specify a classname as your variable type, you can assign to that variable, an object of that class. 

This is a reference type variable.

Other types
There are way more variable types to introduce but let’s not get overwhelmed. We’ll introduce more as we need them. Let’s talk about methods!

4. Methods To Do Things

Think of methods as actions that we can call on to make an object do something. We define a method by giving it a name, what sort of variables we expect as input, what sort of result we will output at the end of the method, and finally the actual code and logic inside of the method!

When we declare a method in the header file of a class, we’re saying that other objects will be able to use these methods on instances of our class. You’ll be declaring your methods in the header file and writing the code to carry out the method in the source file.

In our Superhero example, I might declare a method called “Punch” in Superhero.h. In doing so, I’ll need to write the code in Superhero.m to make the Superhero object do something when the punch method is called.

5. Properties, What?

A property is sort of a variable and a method combined.


OK, OK. I know it’s confusing but think of it this way:

A property is a method that sets or retrieves the value of a variable.

Well, then you might ask, “Why would I need a property if I can have variables that I can set or retrieve values from?”.

Well, you usually use a variable to keep track of something that you will use within your class. If your intention is to expose it for other classes to be able to set and retrieve, you’ll want to use a property.

Under the hood, a property still uses a variable to store the value you assign to the property.

In fact, it’s a best practice to declare a property for something that you want other classes to be able access or interact with.

This brings us to another point:

6. Public Versus Private

So far, we’ve been talking as if everything was public but when you declare something, you need to consider the scope of it. Should that method really be accessible for everyone? Should that variable be exposed to only my class or to everyone?

When a variable or method is declared as private, other objects won’t be able to set/retrieve those variables or call on those methods of your class. In fact, they won’t even know about them.

Only the code that you write within the source file can use the private variables and private methods. Other classes won’t be able to.

When would you want to use private?
For methods and variables that aren’t anyone else’s business, you can use the private keyword to limit the access to them. This eliminates some guess-work when it comes to debugging your application and trying to see why some variables don’t have values that you expect them to have because you can rule out the possibility of other objects changing the value. If it’s a private variable, you know that it can only be changed by the code in that same class.

No one is stopping you from making everything public but it’s a good practice to limit the scope of your variables and methods if they don’t need to be public.

Now what kind of iPhone app development tutorial would this be without examples? Let’s jump right into some Objective-C code implementing the stuff we talked about earlier in the article!

7. Defining A Class In Objective-C

Let’s re-use our Superhero example.

When we create a new class, we have the header file (.h) and source file (.m).

The header file in Objective-C
Here’s what our header file will look like:

A Comment About Comments: 

The green text that’s specified with “//” is a comment. Comments are just statements for the developer to leave remarks for himself or other people reading their code. It won’t affect anything.
Anything after “//” is considered a comment.
If you’ve got a large block of text you want to mark as comment, you can wrap it with “/*” and “*/”. Anything between those two tags will be considered a comment.

In our header file, there’s an import statement and that’s basically to let this Superhero class know about other classes and their respective header file.

Remember, a header file tells other classes what variables, methods and properties are available with your class. So if your class wants to refer to stuff in another class, you have to import their header file.

In this case, we’re importing the Header file of some core Apple classes.

Next, you also notice something beside the name of our class. What is this “: NSObject”?

This is another object oriented programming concept called Inheritance.

8. About Class Inheritance

Not in the sense of money, but in every other sense, Superhero is going to “inherit” all the methods, properties and variables of a class called “NSObject”.

For example, if I was going to create a Spiderman class and I noticed that my Spiderman and Ironman class had a lot of methods or properties in common, I could create a Superhero class that had the commonalities, and then get both my Spiderman and Ironman classes to inherit from the Superhero class.

This is good because I won’t have to write duplicate code and in both my Spiderman and Ironman class and now if I wanted to change something in that common method or property, I only have to change it in one place (in the Superhero class) rather then in two places.

Superhero Tip: Always try to reuse code wherever you can!

Anyways, we got a little side tracked! But that was a really important concept to understand.

Onto the source file!

The source file in Objective-C
Here’s what our Implementation file will look like:

By default, your source file will have an import statement for your header file or else it wouldn’t know what variables, properties or methods to implement!

9. How To Declare And Use Variables In Objective-C

We have to give Superhero some stats right? Let’s declare some variables in our Superhero class to keep track of them.


In the code above, we’ve defined several integers to keep track of vital statistics (lines 5-8).
We’ve defined a boolean variable to keep track if our Superhero currently has lasers or not.
And finally we’ve declared an NSString variable to track a piece of text that we’ll use as our Superhero’s greeting message later.

Remember what we talked about earlier regarding scope. These variables are private because they’re declared within the curly braces underneath line 3 and we want them that way. If we want to expose something that another class would be able to set and retrieve, we use properties.

Why did we put an underscore in front of all of our variable names? This is a common naming convention to easily distinguish variables that are private. A naming convention is a system or standard that you follow to name all of your variables, methods and properties so that they are consistently named and the code throughout your app is nice, neat and orderly.

Programmers like things neat and orderly. It’s logical!

10. Declaring And Using Properties In Objective-C

If we wanted to declare a property for our class so that other classes could access it, we would declare it in the header file like this:


Notice in line 13, we’ve declared a property. There are a couple of key things to note here.

First of all, we’re always going to start with “@property”.

Next, we have two keywords “nonatomic” and “strong”. Let’s talk about “nonatomic” first.

In order to understand what nonatomic means, you have to understand that when we’re writing code we can specify some commands to run in another thread. Thus, you can have parts of your code running and executing in parallel! At some point, those other threads that you sent off to do some work will return to the main thread.

Now imagine if multiple threads are trying to set and retrieve the property of an object simultaneously. This can lead to unexpected behaviour and most likely app crashes!

By default, your property will be “atomic”. What this means is that there will be some overhead added to your code to implement an object-level lock which will prevent that from happening. Imagine that your property is a nightclub and there’s a bouncer in front of your property, ensuring that each thread waits in line to set the property! This is what programmers call “thread-safe”.

So alternatively, if we specify “nonatomic” for our property, that means we’re saying that we don’t need the extra overhead to make our property thread-safe. Maybe because we don’t anticipate multiple threads setting it at the same time, or maybe we’re not using multi-threading in our code.

Ok, so now, what about “strong”? Again, i’ll have to defer to the section on Memory further below!

Next up, we have the property Type. Same thing as specifying a variable type; we want to tell others what type of values this property can have.

And the last part is giving a name to the property. This will be the name that other classes will access the property by.

How would you access or set a property of an object in Objective-C?
Let’s say you had a variable called mySuperhero of type Superhero, that was keeping track of a Superhero object.
You could set the value of a property like this:

This would put the value 9 into that objects stamina property.

And to access that value, you would just say write something like this:

This would assign the value 9 to the variable stamina.

11. How To Declare And Use Methods In Objective-C

And now we arrive at how to declare methods.

Remember that declaring a method involves specifying a method name, the types of variables it expects as input the variable type that it is expected to output and a scope for the method.

Let’s say we wanted to declare a method for our Superhero named “Fight” with the intention of attacking our super villains.

We would declare it in the Header file like this:


On line 15, we’re declaring the Fight method. Let’s break this down.

The dash “-” (yes even the dash means something!) signifies that this is an instance method. This means that you can call this method on an instance of this class. It relates to a specific instance of an object of this class type. This it the scope of the method.

The alternative is a “+” which means that this is a “Static” method. We don’t need to know about that now, so let’s move on to the next part.

The “(int)” part is the return type of the method. What’s inside the brackets tells us what type of value we can expect to be returned. In this case, it’s “int” meaning that we’ll expect an int value to be returned as the result of this method. This is the return type of the method

The return value could also be “void”. As in, there is no expected value to be returned. This method will take some input and perform some action but will not return any value. However, don’t try to use the keyword, “void”, as a variable type, because you can’t. It doesn’t make sense!

The following part is the method name, “Fight”. Other classes will call this method by this name.

If our method didn’t accept any parameters, that would be it. However, in our example, we have a colon “:” followed by “(int)enemyStamina”. The colon is always followed by a parameter and in our example, the method expects a single parameter as input and it should be of type int. The parameter name, “enemyStamina”, should give some indication as to what that parameter represents; in this case, the enemy’s health! These are the parameter(s) of the method. (Note: Later on in Part 2, you’ll see how to declare a method with multiple parameters).

Finally, the semi-colon at the end of the line tells us that is the end of that statement.

Together, all these elements form the method signature.

We’re not done yet! So far, we’ve defined the method in the Header file but we’ve still got to implement the method in the Implementation file. That is, write the code for the method to actually do what it’s suppose to do!

In Superhero.m, it’ll look like this:

In the Implementation file, you’ll notice that the method signature looks exactly the same as it does in the header file however, there is a block of code inside curly braces right below it. This is where we write the code for this method.

We’ve got two lines of code. On line 7, we’re declaring a new variable of type int called “resultingStamina” and we’re also assigning a value to it. We’re assigning the value of the int parameter that is passed in, minus five. So if the enemyStamina that is passed in has a value of 9, the resultingStamina variable will contain 4.

In line 9, we “return” the variable resultingStamina as the resulting output for the method. Notice that the variable type of the variable we’re returning matches the return type of the method we specified in the Header file! The return keyword is reserved for specifying or “returning” the expected method output.

How would you call the method on a Superhero object? Well, let’s say you had a variable called otherSuperhero of type Superhero, that was keeping track of an Superhero object.

You would call the Fight method like this:

Whoa, there are so many things happening in this statement! First of all, we’re calling the Fight method of otherSuperhero.

Secondly, the Fight method needs an input of int value type remember? So we’re passing in the value in the stamina property of another Superhero object called mySuperhero.

Finally, we’re taking the result of the Fight method and assigning it to the variable resultingHealth.

What would the value of resultingHealth be?

If you remember above in the property section, we set mySuperhero.Stamina = 9, right?

So since the Fight method takes that value and subtracts 5 from it, the value in resultingHealth will be 4.

12. Instances, References And Memory (not the kids card game!)

I’m not referring to that old card game you used to play as a kid where you have all of the cards face down and you try to flip over two of the same card. I’m talking about computer memory!

Your iPhone only has a limited amount of memory. Every object you create will use up some of that memory and when you’re done with that object, it gets destroyed and the memory it took up gets freed to be used for something else.

To make things even more complicated, there are two types of memory, Stack and Heap. The stack is for value type variables and the heap is for reference type objects.

To give you a visual representation of the stack, imagine it like a stack of books. When you allocate memory, you put a book on top of the stack. If you wanted to free memory, you would take the top book off first. This is called LIFO, or last-in-first-out. The last one in, is the first one out like in our stack of books analogy.

With a heap, think of it like a row of mailboxes, each box having its own address. When we allocate memory on the Heap, a mailbox gets picked and the actual object resides in the mailbox.

So this brings us back to the notion of instances of our class. Remember, our class is just a mould or blueprint that we use to create instances of objects of that class. And it’s the actual objects that will interact with each other.

Here’s what a statement to allocate an object looks like:

Let’s talk about the statement as a whole. That statement is creating an instance of the Superhero class by allocating memory for it on the Heap, then calling the method “init” on it and finally the variable *instanceOfSuperhero is being assigned the address of the allocated object.

Did you get that?

When we call alloc on our classname, it returns an instance of that class and then we call the init method on it which initializes the class and returns the same object. The init method is where we can set default values for variables and do anything else we need to get the object ready for use.

Because objects are always allocated on the Heap which is addressed based, whenever we declare a variable to keep track of it, the variable doesn’t actually store the object. The variable is actually a pointer to the memory location of the object (or the mailbox in our analogy before). We denote this by adding the asterisk (*) in front of the variable name.

Any variable that refers to an object holds the memory location of the object, and NOT the object itself. If multiple variables are keeping track of an object, each of those variables is basically holding an address to that object.

Reference counting
Because there’s a limited amount of memory available to your application, if you allocate and create too many new instances of objects, you could hit that limit (bad things will happen to your app. iOS will probably close it!).

It’s important that we dispose of the objects we no longer need or use and free up the memory for other uses. The good thing is that you don’t have to manually do this. In iOS 5.0+, this is handled by ARC (automatic reference counting).

So how do we know when an object is no longer needed?

This is where reference counting comes into play. Each object has a count of references to it. The idea is that if there are no variables referring to it, chances are it won’t be used anymore. If a variable is keeping track of an object, then there’s a chance that it could be used.

Remember when we declared our property earlier on? I told you that I’d explain what “strong” meant. Basically, “strong” means that if the property referencing an object, it will increase the reference count of that object. The alternative to “strong” is “weak”.

If you specify “weak” when you declare your property, it doesn’t increase the reference count of the object so there may be a chance that the object becomes deallocated and the memory is freed, even if you still have a reference to it via your property. Later in the series, we’ll realize when we use “weak”, but usually we will want a “strong” reference to the object.

Let’s Summarize

If you’ve gotten this far into the post then you deserve a huge pat on the back! That was a lot to absorb and we introduced many programming concepts but you’re well underway in your journey to build iPhone and iPad apps!

Below is a recap the main concepts we went through. See if you can recall the main points of each topic as you move down the list. If anything is fuzzy in your memory, I recommend you to give this article another read! On the other hand, if you breezed past this material and want to go deeper into understanding these topics, you can visit the Apple Objective-C Primer.

-Classes and class inheritance
-Variables and variable types
-Public vs private
-How to define a class in Objective-C
-How to declare and use variables, methods and properties in Objective-C
-Memory allocation and reference counting

What’s next?

In the next part of this series, you’ll dive right into code! We’ll talk about control structures and data structures.

Go To Part 2

Let’s improve this article together! 

I want to make this series and this article in particular the best and easiest to understand resource for beginners to learn how to develop iPhone apps. If you’ve got any feedback, good or bad, please let me know via the comments below so I can update parts which are confusing, add more examples and to continue updating this resource.

And if you’ve enjoyed this article or you know someone who might be interested in learning how to build iOS apps, please share this series with them. It’s targeted at the non-programmer (sort of like an iPhone application development for dummies book) so anyone you know will be able to pick this up and progress towards developing iPhone apps!

174 thoughts on “How To Make iPhone Apps – Object Oriented Programming and Classes”

  1. Really enjoyed the article–very informative without being patronizing in general. It will take a few more reads to really absorb all the info, but it’s all presented in a relatively logical format. One issue is that the article has a number of grammatical errors, some of which affect the way the article reads. I would be happy to edit it for you if you’d like

  2. I have no experience in programming and this may not be for me but at first I was thinkin alright i can handle this (in the concepts tutorial) but then on step one i have no idea whats going on i feel like for the first step for people with “no programming expirience” it’s a little bit too complex. Just my opinion though thanks.

  3. Thank you for creating this site, I have a few ideas for mobile apps and didnt know what language to begin studying but you have definitely pointed me in the right direction. I want to know if everything you have in these articles are enough to begin creating my own iphone app or should I also look for other objective-c courses. Also I’m a computer science major (very new to programming) and we are learning Java, I dont even think they teach Objective-C smh

  4. Hey Chris. I am blown away by your excellent teaching skills. This post not only was extremely informative, it also was engaging and I appreciated how you went the extra mile to explain stuff, draw diagrams, and reference outside source material.

    Being a first time developer, most of this stuff made sense, but I definitely have some questions. There are quite a few. Maybe you could incorporate these into your post if you find they could benefit others. I have ordered these questions from those that won’t let me sleep at night first, so if you can only answer a few, I guess answer them in the order I write them:

    1. Private vs. Public variables. Are children classes able to access the private variables of their parents? Why are string variables reference variables? If string variables & class name variables are always going to be reference type, why do we have to include the asterisk when declaring them? I would like an example of a private & a public variable in a video game context. For example, if a hero is battling an enemy and inflicts damage on a specific enemy instance, should the enemy’s health be public or private? If it is public, are specific instances able to hold different vales for their health (for example, I only want one enemy instance to lose its health when I attack it).

    2. “int resultingHealth = [otherSuperhero Fight: mySuperhero.Stamina];” I have some questions about this line of code. To my understanding, it appears that we are calling a private variable resultingHealth and setting its value based the Fight method which is being called in a particular instance otherSuperhero. If method code resides within a class, why do we need to designate a specific objects to execute it? All instances within the SuperHero class share the same method code, so why do we need to specify a specific instance? Furthermore, why are we calling upon a different instance of SuperHero class (mySuperhero) and look up its stamina? Is this object responsible for keeping track of values, and not actually a second superhero character on screen? Within what instance will this code apply to? Sorry this might seem confusing, but what i basically want to know more about the difference between instances and classes, and how these variables are uniquely applied to separate instances within a class.

    3. Header (.h) file vs Implementation (.m) file. During a game, is the code in the header file only referenced when a specific instance of a class is created? Is the implementation file accessed repeatedly over and over again by the application in order to receive input? Maybe I’m not thinking about this in the right way. I basically want to know more about how the app handles feedback over time. I know we haven’t gotten into if statements yet, but how many times are if statements looked over by the app every second? When declaring methods in the header file, why do we need to re-declare them in the implementation file. This seems tedious. Also, does passing through an input variable in a method statement mean that we can only access that particular variable within the method? Is that why you had to declare a new variable within the method? Is this a temporary variable, whose purpose it just to store information for a short period of time and then transfer this to another value? Is this some form of the diagram you were talking about (I think it was called MVC).

    What I am most interested in moving forward:
    – Managing several instances of the same class. For example, multiple enemies, How do you keep track of them, keep their variables separate from each other
    – Creating efficient code that takes up the least amount of memory possible.

    If you’ve gotten this far, thanks for reading! Hopefully I didn’t scare you off. Again, please don’t feel you have to answer all of them, but at least 1 would be awesome! Thanks again!

    • Hey Tyler, thanks for reading! I’ve tried my best to answer your questions as clearly as possible!

      1. If the child class wants to access some data from the parent class, the parent class should expose methods and properties that other classes can access. If you only want those variables exposed to children class, then you can declare them as “protected”. That is specifically accessible for only subclasses.

      String and class type variables are reference types because of the way strings and objects are allocated in memory. Under the hood, values and objects (strings are objects) are allocated in different types of memory. The asterisk signifies that that variable will hold a reference to something.

      In your video game scenario, I would create an Enemy class which would have several public properties like Health, Power, Defense etc.

      Then you can create multiple enemy objects from that class. Although each enemy object has Health, Power, Defense properties, they’re all separate instances and are tracked independantly from each other. So if you attack one enemy object and change the value of that objects healthy property, the other enemy objects are not affected.

      2. You’ll probably realize that answer to this question after reading the last bit of my answer to your first question! A class is merely a blueprint that you designed. That blueprint is used to reproduce multiple “instances” (aka objects) of that class type which behave exactly as you’ve designed it. Each object has the same methods, variables and properties but each is tracked independantly from each other.

      3. App programming is different from game programming in that with games, there’s a “game loop” which just keeps looping and updating positions of sprites, checking for user input etc.. I think that’s the type of thinking you’re trying to apply here.

      However, app programming thinking is more reactive. You hook up methods to user elements and those methods get triggered if something happens to that user element. If the method is not hooked up to anything, it won’t get executed unless you explicitly call it.

      If you’re interested in game programming, look up tutorials on SpriteKit which is the framework Apple provides to build games.

      • Thanks so much Chris for your detailed response. I’ll take a look at SpriteKit. Following your tutorials all the way through – extremely helpful!

  5. I have a question about this:

    Reference counting
    So how do we know when an object is no longer needed?
    This is where reference counting comes into play. Each object has a count of references to it. The idea is that if there are no variables referring to it, chances are it won’t be used anymore. If a variable is keeping track of an object, then there’s a chance that it could be used.

    Can you please explain (for a beginner ), how a variable can “keep track of an object”?

    Many thanks.

  6. Hey Chris, just some feedback for ya:
    Thank you for this page, it is a fantastically useful resource and I find myself constantly referring back to it for instant assistance. My only grime is that I have not found an obviously direct way of navigating to it other than through one of the “here” links scattered throughout your tutorials. Further, the page itself is only navigated by scrolling up and down through reams of articles (unless, of course, I’m missing something – I’m the kind of person who gets frustrated trying to push open clearly labelled “pull” doors!)
    My suggestion is to have a glossary/reference page which may be accessed through either a website search bar or link and navigated with alphabetical links or, again, a search bar.
    I hope this is useful and constructive!
    Love your work!

  7. Hi Chris,

    These are great tutorials! Once I complete this series I am going to dive into the Membership courseware which I just signed up for.

    I do have a question regarding conventions. I have always liked to use Hungarian Notataion ( and I see in most examples on the web and books that this convention is not used. I love this convention because for me it self documents my code and makes it so much more understandable. Do you know why this convention is not used and do you know any reason why I shouldn’t use this convention?

    Thank you again for making it fun and interesting to learn. Much appreciated!

  8. First off, thank you for this. I’ve always wanted to write code, but was put off by not having a formal educational background and had been told too many times that it was “too hard” and I “would never learn”. But, I have to say that I’m starting to get the gist of this. The biggest thing for me is that as I read along, I’m writing things out as I go. When I get to the parts like “declare a method for our Superhero named “Fight” with the intention of attacking our super villains.” I want to test myself here and try to write this line of code myself, only to see “#” “-” “+” & “@” later on in the actual code that you have provided. It would be helpful (at least to me) to understand the use of these modifiers (I guess thats what they are, I still don’t really know how they fit in). Something along explaining a few more of the basic items would really go a long way for someone like me with absolutely zero experience in C, nonetheless Objective-C.

    Keep up the great work, as I will continue to follow along til I get this figured out.

  9. Hey Chris, I filled out a contact form on this site but maybe it isnt accessed as much as the comments are. I want to know if with what I learn from you (basically no programming exp here) that I can make my app, I just dont want others to know my idea. Would you email me at Thanks man.

    • no, you can’t, you are far from being able to code at a commercial level, even being if you where able to code it, there are many other aspects to take into account when creating a software product.

  10. Hard read. Big step from the last tut. Think I got most if it and will move onto the next one. I think I need to get to the hands on stuff to fuse these concepts onto my brain.

    My overall aim is to create an app that can look after an inventory of food and ingredients. Users will be able to add new ingredients and create recipes from the existing inventory. A calculator of some sorts will work out how much these will cost to make.

    This is something I can do with an app yeah?

    • Hey Daniel, yeah you definitely need to try some of it out!
      Otherwise i guarantee that even if you get to the end of the articles, you’ll have forgotten it all by the time you get around to trying it out for real.

      Yeah that apps sounds wicked!

  11. Great tutorial! i really want to learn obj-c for iphone since last year, but bit afraid of learning it. Your tut give me more understanding for all objects and terms used in obj-c. Thanks Chris!

  12. Chris! YOU ROCK! As an educator myself, I have had a VERY hard time even wrapping my head around how to explain programming to non-programmers. I’ve had 20+ years in the industry, but never attempted programming because it was always taught by some “programmer” (no offense) who couldn’t bring the concepts down to a base level. Your examples are PERFECT! They work for me and I TOTALLY got it from the start! Keep up the GREAT work and I’m hoping my APP knowledge explodes as quickly as your praise from all of us newbies!

  13. Thank you very much for this awesome tut! It helps me so much to get in the Objective-C.
    I am little bit confused with this part of the code in this article.
    You gave few examples of code and then you gave this:

    mySuperhero.Stamina = 9;

    int stamina = mySuperhero.Stamina;

    and later this:

    int resultingHealth = [otherSuperhero Fight: mySuperhero.Stamina];

    Where do these strings actually go to work with the rest of the code?
    XCode gives errors about it )

    Once again thank you

    • Hi Chris, great tutorial, your teaching method is making a lot of sense for me. I am scratching head with Mike here at the part [otherSuperhero ……] What is the otherSuperhero? is it a class, function etc..?

      • otherSuperhero is another Superhero object!

        Remember that a class is a blueprint used to create many objects from it and it’s the objects that interact with each other.

        So from the Superhero class, we created two objects.

        Don’t worry if you don’t get it right away. This is the hardest thing to wrap your head around when you first start programming. Did you read this article?

        • Thanks again Chris for the pointer. I am still processing all these new concepts and hopefully they will click soon. 🙂

    • Hey Mike, the code doesn’t really go anywhere because we’re not building an app in this situation but I just wanted to demonstrate some examples of using properties and methods.

      This line demonstrates setting a property called “Stamina”
      mySuperhero.Stamina = 9;

      This line demonstrates retrieving the value from the “Stamina” property
      int stamina = mySuperhero.Stamina;

      This line demonstrates called a method called “Fight” and passing in a parameter to it.

      For a more practical example, check out the videos in the “Start here” section in the link up top… you’ll see me actually use properties and methods and i think it will make a lot more sense.

      • THANK YOU!!!

        I am also trying to get these new terms to stick in my head “atomic”. “nonatomic” “strong” and the use of “@property”

        To help me understand, can you expand your super hero example, by giving some practical reasons when you would set different variables in different ways.

        These examples would really help me understand the concepts, by relating the concepts to practical uses of the different ways.
        Could you please fill in the “……..” below.

        Q. When would it be best to set Stamina like this:
        @property (nonatomic) int Stamina;
        A. When you are making a game where you want to share the variable with …….

        Q. When would it be best to set Stamina like this:
        int _stamina;
        A. When you are making a game where you want to share the variable with …….

        Q. When would it be best to set Stamina as “strong”, something like this:
        @property (nonatomic, strong) int Stamina;
        A. When you are making a game where you want to share the variable with …….

        Thanks again !!!
        I really got a lot from your clear and systematic explanations.

  14. Hi Chris

    I’d like to start by saying well done and thank you for writing these articles. Very simple, fun and easy to understand. I’v read your core programming concepts tutorial last night, and now I’m halfway through your object orientated and programming classes article. I’d appreciate it so much if you could advise me please.

    Like many others, I believe I have an excellent idea for an app, which happens to be a whole new concept for which there is currently no app available. I’v done a little market research and I have been overwhelmed with positive responses. I’m excited because I think the app will be a big hit. So now, I have to go ahead and make it happen!

    I’m a graduate from law school and an amateur boxer, so I have no programming knowledge (again like so many others), but I am willing to put in all the time and effort necessary. Luckily, I have a lot of free time right now, and I even have a good source for funding, if and when its needed. Articles like yours are a gift for me, so thanks again.

    My questions to you are:

    1) What’s your initial thoughts on how I should begin my seemingly humongous task of creating my dream app from scratch, to launch both on iOS and Android, baring in mind that I’m willing to learn and put in time and money, but I only have windows computers at home?

    I feel that I will need to slowly build a tight knit team to help me with it, but that at this early stage, I need to learn things myself first

    2) Any tips you can give me on the most efficient way to begin my journey? I am not looking for short cuts, I am willing to do what ever it takes, I just want to make sure my final product is perfect, and of course I don’t want to be wasting time doing things which can be done quicker

    Thanks Chris!

    • Hey Ehsun, that’s really inspiring and you’re approaching it with the right attitude!

      My advice would be to start with either Android or iOS. Don’t overwhelm yourself from the start. Many businesses will focus on iOS first, release it, and then work on the Android version.

      Whether you go Android or iOS first will depend on where you think more of your target audience is.

      You can build Android apps on both PC or Mac, but there’s a site called that makes it affordable to remotely access a Mac for development. I think it costs $10-$20 per month for unlimited use. That may be a low cost way for you to get started without spending too much money on a Mac computer.

      The next piece of advice I would give is that you’ll have to practice while reading/learning so while it’s awesome if you’re understanding the material while you’re reading it but when you actually start to build your first app, you won’t have any idea where to start.

      That’s why it’ll be handy to follow a sort of “build your first app step by step” tutorial and get your feet wet with practicing. With practicing, you’ll hit some roadblocks and wonder how to accomplish something.. that’s when you can ask questions or research into how to overcome it. Then it’s really rinse and repeat and you’ll be fluent in no time.

      Check out the “Start Here” section up top. I need to update the videos for Xcode 5, but i’ve updated the article text for Xcode 5 and updated the screenshots in the article. If you’re learning from those, check out my video course as well. Many beginners are finding success with it.

      Once you get some of the functionality for your app idea working.. then it may be time to bring on board a designer (or contract it out, or design it yourself if you have that skill set) to make the app look nice. This part is very much about creating graphics in a program like Photoshop or the like, and then applying those PNG images into your app.

      Hope that helps!

      • Yep that definitely helps! Thanks a lot mate I appreciate the time you took to advise me, and I will check out your Start Here section too

      • Hey Chris,

        I watched the first few videos in your Start Here section and I instantly understood what you mean when you say that you can’t truly learn the information from the articles unless you are also practicing it, by implementing it. Seeing your videos of Xcode, it looks really fun and I want to get started asap! By the way your speech speed is perfect, easy to follow and not too slow.

        But, I have another question for you. The app I want to develop is going to be complex I think (I say that because its based on storing a lot of data from around the world). It will also be visually impressive (nice graphical images and colours) but it is not a game – its a utility. So with this in mind, do you think that the BEST way forward is to develop it on a mac?

        I have read that there are good programmes out now which allow users to preform cross-platform programming. While this will obviously be a lot more convenient than learning 2 different languages of coding, I am wondering whether Xcode on mac has any distinct advantages to produce my app for iOS, which the other programmes do not offer?

        If getting a mac will offer me the absolute best for releasing my app on iOS, then I am willing to get one. Perhaps if could be a great investment for the future, should I decide to continue making apps. However, if I can do just as well using cross platform programmes, then I will do that.

        Thanks again!

        • Hey Ehsun, unfortunately i dont have much experience with the cross platform solutions. It may be the right solution for you but maybe you can ask them if it will fit your needs. The advantage is that you don’t have to learn two languages but there are probably drawbacks as well.. just make sure that the drawbacks don’t interfere with the type of app you want to build. For example, a drawback could be (i’m just guessing) it’s not as performant and its slower at rendering graphics intensive stuff…

          Best thing to do is find out from them! Maybe they have forums or something.

  15. Just wanted to say thank you for taking the time (and wisdom) to do this. I have a couple different degrees but not in computer science but have always had that natural ability if that’s what it is.. You know the type that all your friends and family calls when they have something wrong with their computers and electronics.. Anyway I figured I might as well add this to the list as I’ve wanted to learn for a long time but don’t want to shell out 1000’s more for a professional education.. Anyway I truly appreciate this follow along and hope u will keep up the good work of helping others because in today’s age most people just aren’t willing to share knowledge! Thanks,

  16. hi Chris, what does to allocate an object mean? and why do you use: Superhero *instanceOfSuperhero = [[Superhero alloc] init]; is the same as: Superhero *instanceOfSuperhero; ?

    • Hey Stefano, this line: “Superhero *instanceOfSuperhero;” is simply declaring a variable that will hold a Superhero object. Right now it is empty.

      When we write “[[Superhero alloc] init]” that is creating a Superhero object from the Superhero class.

      The “=” sign is used to assign something to a variable so if you put all of that together, this line, “Superhero *instanceOfSuperhero = [[Superhero alloc] init];” Is declaring a variable, creating a Superhero object and assigning that object into that variable.

      Now the variable points to that object (you can think of it as the variable tracks or references the object) so that later on when you want to do something with that object, you can use the variable to get a handle on the object.

  17. hi Chris, thank you very much. I got me interested. This site is the best ever. Well i am from Peru. I can understand a little bit english. i can understand it and my aim is to make a Game in an iphone or ipad. I want to know if you can teach how to create games and what is the difference between Corona Sdk and Sprite Kits and what are they? Are they other Applications in order to create applications or are they plugins inside xcode?. Any response would be greatly appreciated.

    • Hey Stefano, thanks for the kind comments! For games, you’ll want to look at Sprite Kit. You’ll still be using Xcode but sprite kit is the framework that you’ll be using inside of Xcode! Look for Sprite Kit tutorials because my knowledge in it is pretty basic!

  18. Thank you very much Chris! This article is fantastic and definitely a lot easier to read / comprehend than anything else I have found. I’m very interested in creating a app for distribution on Apple products. If I’m correct with my terminology to meaning. I would have roughly 200 classes will very limited variables. I potentially see it has a research intense project but it will pay off in the long haul. Currently I’m in Afghanistan supporting our U.S. troops. So I’ll try my best to read your tutorial as often as I can. I’m also having to upgrade my OS so I can download CodeX. Downloading the upgrade will take a few days, internet is horrible here in time I will be up and running. I figured while I read your tutorial I can also get familiar with the program I will have to use. I think as I read on I will pick up a lot more information which will answer the questions I have. As for now, thanks a lot!

  19. Hey Chris! Thanks for all your hard work helping us novice. Question for you. If I wanted to develop a simple chatting application with some photo sharing, how many hours would you expect a one man team would have to put in to complete it? Given he or she had the time available with no major distractions.

    • Hey Sean, it could be quite involved because the app communicates with other apps.
      You would need to build a server component to store chat messages and let other chat clients know about messages coming in. You would need the ability to add friends, register/login for an account etc..

      To get a working prototype up and running, maybe two weeks for someone who knows what they’re doing. The first week to build the server side stuff and another week to build a rough iOS client app that communicates with the server.

      And then you would need time to do graphic design, implement the graphics into the app, polish the app up and test and fix issues which could probably be another three weeks.

  20. Hello Chris, thank you for this great tut; helps me a lot to understand the basics of objective-C.
    Question: in the book of Stephen G. Kochan, he explained also memory-management.In every example.h, he uses the notation:
    @autoreleasepool {

    The pool is a mechanism that allows the system to efficiently manage
    the memory the application uses as it creates new object”
    What is your meaning / advise of using always this mechanism?

    • Hey Gurdy, thanks for asking! I’ve never come across it so it made me look it up from here:

      When you’re working with a single threaded app, it will already have it’s own autoreleasepool so you don’t need to manually specify one. There are a couple of scenarios where you’ll want to create your own autoreleasepool though and that is if you create a 2nd thread of execution or when you want to create a smaller, more local autoreleasepool around a section of code that may be memory intensive.

      If you don’t know about creating new threads then you probably don’t have to worry and if you’re not working with memory intensive objects then you probably won’t need it either! The author has probably made it a habit to include it as a good coding practice so that’s why he’s showing it that way.

  21. Thank you for all of this! I am a complete beginner and will have to read it a few times but I am looking forward to learning more. I like your easy to read style 🙂

  22. Hey Chris. I found this article extremely helpful and informative to guide me into building my own app. I’m going to try and squeeze in an article or two each day until I can confidently build my own app for my final major project in my Graphic Design course. Thank you for putting the time and effort into these articles, i’m sure the future me will appreciate it. (the present me does aswell).

  23. Great tutorial i got a little lost but i keep reading and reading again i got to understand it. is really good i would read it again just to make sure i understand everything but for the most part i thing i got allot of it thanks alot for the post is great really is so helpfull

      • Something I wanted to ask about it why do we set property wen we are suppose to set then and where that part I don’t quite get it I understand the nslog is to outout message the nsstring how to store mi data in a variable but I don’t understand what are the property and what I’m suppose todo with them thank you in advanced

        • Hey Fernando, for the most part in storing data, you’ll be using variables.
          Also most of these variables will be private to that object. If you’re confused about public vs private, don’t worry. You’ll reach a point very soon where you’ll have to know it.

          For properties, you’ll find yourself using them most commonly for 2 things:

          1) to store connections to elements created in the Storyboard (you will learn this in lessons ahead)

          2) to store data that is public and accessible by other objects (again, if you don’t know, it’s ok. Because in the future you’ll probably arrive at a situation where you want to do access some data in another object and you’ll remember that you can use properties for it!)

  24. Thanks for the tut, very informative. As an absolute beginner (I have 0 experience with Objective C or any other programming language) it got me very interested, however I am confused with a few things. My ultimate aim is to make an iOS game I’ve had as a basic idea but I don’t know where to start off, short of Xcode?
    Your tut was brilliant but is there an work through kind of example to learn as you build a basic game or example app, to see what you’re doing while doing it and a kind of start to finish/ creating-holding-files-to-testing guide around (if that makes any sense)?

    Still, thanks a lot, the basics of your tut have been the most helpful resource I’ve found so far? Any response would be greatly appreciated!

    • Hey Nick, thanks for reading! If you click “Start Here” at the top of the site, that’s where i have videos that walk through coding together. (starting in vid 4 or so).

      However, if your aim is to build an iOS game, then it’s different from building apps. You’ll want to look up tutorials related to Sprite Kit. If your game is not too animated, such as a card game or word game, then you can still get away with building an app that functions as a game.

      • Thanks so much, will check out “sprite kit” after going through the rest of your tutorials to get a feeler for the basics of an app first. Much appreciated, you’re a legend!

  25. So far i’ve tried to read many books, watched many videos on youtube and you are the only one thats managed to make sense of it all for me. Kudos man, thank you!

  26. Thank you chris, I appreciate your free work sharing it on public.
    I hope to see and read more things like this in future from your site (Control D)

  27. This is a brilliant site, so far all of the articles I’ve read have cleared up a lot of questions – I did a lot of these things without actually realising why!.. I am not new to programming, but I am new to Objective C and it feels quite backwards to me compared to Java. This has been brilliant helping me get on with App development. Thank you!

  28. Great article! I’ve just taken up the project of making an app for my school and was wondering if you could point me in the right direction as to how I could build a data base in which the app would have knowledge of all student’s classes at its disposal (to notify them of assignments and so on…).

    • Hey Felix, to do this, you would need to have a way to access the information from you schools database that contains all of this information. I suppose the first step would be to ask your schools IT department if they have some web service or API to access this student information!

  29. Nice tutorial. I am enjoying reading.

    I need to make an app for intra department information. The information will be displayed page to page and hyperlinked pages with basic fade out transition effects. I know this can be achieved in web browser but requirement is to get it in app and available on app store to be downloaded by any one who requires.

    What do you suggest where should I start from?

    • Hey Rafi, if this is already available via webpages, have you considered making a mobile view for the webpages and then your app is just a webview control displaying the webpages?
      Another thing you can do as well, if your main competency is web and you don’t care about updating the content outside of the app, you can create webpages targeted for mobile view and then include the files in your app. Then it can also be view offline.

      And finally, your option is to go fully native.. My suggestion for learning would be to learn how to transition from view controller to view controller, and learn various ways to lay out your text/images.. if your content is not complex, then labels and imageviews may be enough!

      • Thanks Chris, you are gem of a person .. 2 more questions …

        1. I have made mobile view using jquery mobile framework but looking how to embed that in xcode and publish. Will be thankful if you can share some online resources to understand the basics.

        2. Any learning sources you would suggest for view controller, layout creation and imageviews or you emphasize that I go through your lessons in the same order you have provided here ..

        Thanks in advance.

  30. Hi Chris, great explanation, started to do your ‘course’. have some programming experience but only in matlab and visual basic…. lot of new stuff to learn. I have one question about the upper stuff. you say: Superhero *instanceOfSuperhero = [[Superhero alloc] init];. I think I got that. Only the necessity of the first ‘Superhero’ word I don’t get. you’re making an object (*instanceOfSuperhero) of the class Superhero, by allocating memory and initing this, but why do you need Superhero at the beginning of the sentence? what does that do?

    Thanks a lot for putting all the energy in explaining this to the new bees

    • Hey Jimmy, MatLab is hard! 🙂

      Regarding your question:
      Superhero *instanceOfSuperhero is actually the variable declaration. We’re declaring a variable to store the new object we are going to create.
      A variable is declared via “VariableType variableName”. So in the case above, VariableType is Superhero and *instanceOfSuperhero is our variable name.
      The equal sign (=) is us assigning the new object to the variable.

      Hope that helps!

  31. Thanks for the awesome tutorial Chris Ching. I guess what i would want to be improved would be the examples. perhaps more add on of: (with this our hero can lose damage by other classes) or (this is what creates our heroes stats) and so on… Or perhaps i’m missing the point and should just read it again lol. i’m not really the brightest guy and this is my first tutorial on app building i have read. but it’s been very useful and i intend on finishing all of your tutorials! Thanks again.

    • Hey Kralleb, thanks for your suggestion! I do agree that examples help a lot 🙂 I’ve actually tried to focus more on examples and learning through practice in the BASICS series up top in the “Start Here” link. Please give those a try and let me know what you think!

Leave a Comment