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:
NSString
int
BOOL
double
[Classname]
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.
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.
What??
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:
Superhero.h
// Imports are necessary to let this Class know about // the names, variables, methods and properties of other Classes #import // This is the declaration of our Superhero class // it inherits from NSObject (more on this below) @interface Superhero : NSObject // Right now, we haven't specified any properties, methods or variables @end
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:
Superhero.m
#import "Superhero.h" @implementation Superhero @end
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.
Superhero.h
#import @interface Superhero : NSObject { int _agility; int _strength; int _intelligence; BOOL _hasLasers; NSString *_greeting; } @end
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:
Superhero.h
#import @interface Superhero : NSObject { int _agility; int _strength; int _intelligence; BOOL _hasLasers; NSString *_greeting; } @property (nonatomic, strong) NSString* Name; @property (nonatomic) int Stamina; @end
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:
mySuperhero.Stamina = 9;
This would put the value 9 into that objects stamina property.
And to access that value, you would just say write something like this:
int stamina = mySuperhero.Stamina;
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:
Superhero.h
#import @interface Superhero : NSObject { int _agility; int _strength; int _intelligence; BOOL _hasLasers; NSString *_greeting; } @property (nonatomic, strong) NSString* Name; @property (nonatomic) int Stamina; - (int)Fight:(int)enemyStamina; @end
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:
#import "Superhero.h" @implementation Superhero - (int)Fight:(int)enemyStamina { int resultingStamina = enemyStamina - 5; return resultingStamina; } @end
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:
int resultingHealth = [otherSuperhero Fight: mySuperhero.Stamina];
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:
Superhero *instanceOfSuperhero = [[Superhero alloc] init];
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
-Methods
-Properties
-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
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!
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
Hey Conner, I would really appreciate that! Thank you!
You can reach me with the contact form at the top. Much appreciated!
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.
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
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!
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.
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!
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 (https://en.wikipedia.org/wiki/Hungarian_notation) 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!
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.
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 azucker1@my.smccd.edu? 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.
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!
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!
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!
Thanks Katt! That’s really encouraging for me to hear 🙂
I now understand the meaning of life (Objective C)..
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? https://codewithchris.com/learn-programming/
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.
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 macincloud.com 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!
Chris
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.
This is a fantastic tutorial, Chris! I wish I had this before i started Objective C!
Thanks Stan! That means a lot to me!
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,
Hey Jim Evans, thanks for reading the tutorials and taking the time to comment! It’s definitely a self-teachable thing so keep at it 🙂
Great article! Clear and easy to understand! Thank You!
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.
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!
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!
It’s awesome what you’re doing out there. Kudos to you and do keep me updated on your learning!
This is great thank you, probably the best iOS intro tutorial I’ve read so far.
Thanks for reading Ri! And i really appreciate the comment 🙂
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.
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: https://stackoverflow.com/questions/9086913/why-is-autoreleasepool-still-needed-with-arc
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.
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 🙂
Hey Jill, Thanks for reading and let me know if you have any questions!
It’s a little tough to wrap your head around at first, but you’ll get it!
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).
Hey Jonathan, thanks for reading along and I wish you luck with your project! If there’s something that’s unclear. Please let me know!
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
Thanks for reading Fernando! Feel free to ask me any questions if you don’t understand a concept!
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!)
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!
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!
Thanks Lee, that means a lot to me!
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)
Thanks for reading eyestra1n!
great tutorial. worth the time spent reading it. got me curious for more.
Thanks Rafael! I hope to be posting a bit more regularly once i finish beefing up the paid course!
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!
Hey Alicia, thank you, i really appreciate your time to read it and comment! 🙂
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!
Very informative
I enjoyed reading here and learnt a lot thank you very much !
thank you and I’m glad it helped! 🙂
Great primer tutorial, Chris. Thanks for taking the time to create this.
I really appreciate the comment! Thanks for reading!
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.
Hey Rafi, look into tutorials using “uiwebview”
My Basics series will address the layout creation or I’d also recommend raywenderlich.com, appcoda.com and geekylemon.com
Thanks Chris,
I am on it.
excellent tutorial…..perfect for a beginner like me.
Hey Lakshmi, thanks for reading and let me know if you have any questions. I’d love to help!
Thanks a ton for this great tutorial! It is instantly recognisable that you spent a lot of time working on this.
I appreciate your time in reading it too! 🙂
Hello Chris! Your tutorials are great! Keep it up. 🙂
Thanks for the kind words Jerald and glad you enjoyed them!
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!
Chris
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!
hi, thanks for this tutorial. It’s helped me gain more understanding on the concept of app programming works. Just one point of constructive criticism if I may. One thing I would like is to have seen though is a working example of this app at the start though as I can relate more to reverse engineering when first learning something. If I see what it does I understand more of the coding functions and how they may interact. As a first timer to app programming I would relate more to seeing the app first then having references back to how parts of the app work If that makes sense. I’ve not read any more tutorials yet so you may have this covered in other sections but its just my first impression. Thanks again. D.
Hey Darren, I never thought of that. Thank you for the suggestion! I’ve made a note to incorporate it into the series after I release my course. Thanks!
EXCELLENT refresher! Thank you, just getting back into it all of OBj-c after lots of javascript work stuff. Next up is iOS 7 and UIDynamics.
At this line “The following part is the method name, “Fight”. Other classes will call this method by this name.”
You forgot to explain the :
I know how it works but just noticed the omission
Awesome!! Glad to have you back 🙂
Thank you for the input! I’ve updated the article.
Great job Chris, i really enjoyed this. i am begginer and there is a lot to take in but i can see progress. I feel like pehaps a diagram would do a great job in explaining this faster. Thanks a lot.
Thats awesome Washe! Thanks for reading and the suggestion! I will update it when i get a chance.
Excellent overview for visual learners. This helped clear up a few things for me. Thank you ^_^
Thanks Lita! Diagrams always help 🙂
Great job, Chris! I’m a Java programmer hoping to add Objective C to my skill set, and this was a GREAT way to gain an understanding of how Java concepts map to Objective C syntax.
One small thing, though, and I wish I had a way to send this feedback privately. There are a number of grammatical goofs that kept distracting me from the content. Mostly it was using the wrong “its” (it’s is “it is,” not the possessive; if something belongs to “it,” then that thing is “its”), though you also butchered “begs the question.” Most people do, and it is a bete noire of mine!
Hello Boots, THANK YOU!
That was awesome. I had to look up the proper use of “begs the question” and it’s versus its but I’m glad I did and I’m glad you pointed it out!
I fixed the errors in this article relating to those two goofs and it’s going to be something I’ll remember for all of the writing I do in the future.
I don’t have the capacity to go through all the old articles right now but again, your feedback was much appreciated! Thanks!
Hi Chris,
Awesome advice and instruction for newbies like myself. However, I have a problem getting the map to load. Here is the message from the Log Navigator, pointing to my viewDidAppear method:
“Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘-[UIView setRegion:animated:]: unrecognized selector sent to instance 0x9a95da0′”
I wonder what I did wrong?
Hey Loren,
From the code above, the thing that is wrong is that you’re trying to call the “setRegion” method on the UIView. Instead, you should call that method on the MapView object.
In the tutorial, i’ve got a property referencing the MapView so i can write “[self.mapView setRegion…]”
Hope that helps!
Chris
Chris
It is very obvious that you dedicated a lot of time constructing these, and I would like to thank you for your time. It is in a very easy to read, and understand format. Great job, and thanks again.
Hey Bryce, your comment is much appreciated. Thank you for reading!
Outstanding Chris – I really enjoyed your writing style.
I really appreciate your time, Alistair!
good work
Thanks for reading, Gaurav!
Superb.. loved it.. great job putting the content is such easy format
thanks for reading and taking the time to comment, Santhosh!
I don’t know how I was randomly lead to this article, but I am so grateful I am looking forward to religiously follow these and work my way to app development , its the language of the future !
Thanks for reading, Murtaza!
Hi Chris,
I can see a LOT of appreciation here for your hard work but I still thought it necessary to scroll and give you props.
I have looked at codeacademy, learningcodethehardway, a lot of the links on the first page of google search for “programming ios apps” and even considered purchasing a treehouse subscription. I’m glad I stumbled upon this, you have a refreshing take on introductions to programming and you have done a great job of explaining things with clarity and appropriate examples.
I am looking forward to Parts 2 to 5 and urge you to continue with this because you have a knack for teaching my friend.
Most appreciative and, well wishes from Australia mate
Hello Chuck, I can’t express how much I appreciate your message! I never thought that this many people would be reading and I’m glad that you guys are learning from my tutorials. Reading these messages really is the best part of the day! 🙂
thanks…i really enjoyed reading this…looking forward to exploring the world of programming! Thanks for taking the time!
Thanks for reading, Nicole. Glad you’re enjoying it 🙂
Thank you Mukul! I’ve updated the link to your suggestion which is perfect 🙂
I am having window 7 os…
where to write this code.
Sorry Neeraj 🙁 You’ll need a mac!
I’m only 12 and I understood most of that mainly because of the simple terms and analogies like the superhero or the letterboxes. I just had one question though, when you use all the symbols and new lines in the coding examples if you didn’t specify a need for them were they still important or were they just to keep it neat and clear?
Hello! Thanks for taking the time to comment and read the material! The new lines are just to keep it neat and clear but the symbols are necessary. They’re part of the objective-c language. They’ll probably seem really foreign right now but over time you’ll understand which brackets you need to use. I’ve gotten this question (about the symbols) quite a bit, so I’ll create a cheatsheet or something for the symbols. Thanks again!
Hi Chris,
Excellent overview! I didn’t “get it” all, but I’m 47 and never programmed further than HTML. I’ll re-read a couple times to see if I can get it. I’ve never seen coding explained in such an easy way before. I appreciate it a lot. Will show my appreciation as I continue through the course with a donation. Just not sure if it will be worth anything to me yet, as I may not continue and just decide to pay someone to do my iPhone apps.
Looking forward to grasping all this and moving on to your video series I saw on Youtube. I hope this is all worth your while.
Cheers,
Vern
Hey Vern, I really appreciate the time you took to comment and thank you for the generosity! I love that you’re giving it a shot to learn yourself. Also, I would recommend to click the “Start here” link at the top and go through those videos as it’s my 2nd attempt at teaching a beginner’s course and i believe that it’s much easier to understand!
Thanks
Chris
I have what I think is a great idea for an app… Please call me thick but i’m really lost here.. I have no experience at all in this field and reading this just confused me to the max….
Hey Daz, I’m glad you commented or else I wouldn’t have been able to help you!
I just wanted to make sure, have you tried the Basics series first? Those lessons are better suited for a beginner. You can access them via the “Start Here” link at the top of the page.
Please let me know what you think of those!
Chris
I have 1 suggestion for your series. Can you specify what kind of hardware/software that we need to make iphone apps? I’m excited to make them, but I’m afraid that I cannot with a Windows 7 OS.
Otherwise, thanks for this article Chris! It’s really informative, and now I’m pumped to make apps.
Hey Wayne, thanks for the suggestion! I’ve mentioned what hardware/software is needed in the “Tools” section above, but you’re right, i should include it here! Unfortunately, you’ll need a mac 🙁 There are people who’ve gotten hackintoshs running on PC, but it seems to be a hit or miss..
hei man good work, really good article but section 11 and 12 is still too complicated I missed many points from section 11 middle to the rest. If you could possibly edit section 11 and 12 it would be more than fantastic!
Thank you for the feedback Paul! I think it’ll be easier to understand with diagrams..
That’s what i’ll do!
This is so helpful! Just one suggestion, I’m sorry if you already did this and i didn’t notice but could you make a sort of key showing all the symbols and the meanings that we can print because all the * and – are confusing and I’m not sure what they mean, thanks for the help!
Hey Matej, thanks for the feedback, i’m working on an Objective-C cheatsheet for everyone!
Hi Chris,
Nice tutorial and easy to understand from basics.
One small question, what is the implication of square brackets in
Superhero *instanceOfSuperhero = [[Superhero alloc] init]?
Hey Ranajit, that line is creating a new Superhero object and then assigning it to a variable called “instanceOfSuperhero”.
To get to details, the square brackets is for calling methods. In the line above, “[Superhero alloc]” is calling the alloc class method of the Superhero class and this will return a new Superhero object. Then the outside brackets is for calling the “init” method on the returned object from “[Superhero alloc]”.
Hope that helps!
Hello, im think its great way you are doing this but this is to hard to understand for me without and illustrations. so i would recommend you to make some powerpoint pictures to theese articles to make it more understandable for people that are not used to thinking this way about things. i guess. but your youtube tutorials are great. 🙂
Thanks for the feedback Sigvart! I’m making a conscious effort to use more diagrams and screenshots. Please check out the new Basics series (Click “Start Here” at the top of the site). Would love any feedback you have on the new lessons! Thanks, Chris
Holy Cow this is going to take some time to figure out.. Can I pay you to write an app for me? Or you can be part owner if you’re interested;) It’s probably worth a trillion dollars lol.
Hello! Sorry, but i’m not taking on any freelance work or partnerships for now! 🙁
Thanks Chris for making these tutorials. They are very different from the other tutorials out there – I am finally understanding how it works instead of just following someone’s “do this, do that” list.
Keep up the great work!!!
Thank you Loralea, that’s exactly what I’m trying to do: explain so that people understand rather than just pointing out what to do.
Thank you so much!
Hi Chris, thanks for helping us out on learning to code with Objective-C. At first I subscribed to the Stanford classes but that was just too overwhelming seeing that I have never did coding before. I need to develop an App for my desertion and learning from you will make the journey in building this App just so much easier. I will need some assistance in a later stage and was wondering if it is possible to ask you a few questions then. Keep up the great work you doing. 😉 regards, Franco
Hello Franco,
I’m glad that my material can help people and congrats on taking this journey to learn programming. It’s fun!
Please send me any questions you may have!
Chris
Hey Chris,
Man you are awesome, I just jumped from finishing 5 videos of Xcode from your youtube channel as you said if I’m new i should read these first, I always had this issue i never understood these basics of Objective-c and everywhere else they just keep teaching you like you know these basics, this time I’m really enjoying and not going to quit again, we all advantage takers must donate Chris for this effort, so that keeps him motivated, the time Ill learn something Ill send you gift straight from Pakistan (Thats my Country), now you are my first GURU about programming.
Best Regards
Junaid Kureshi
Hello Junaid, wow, thanks for the kind words 🙂 No need to send me anything; your words are enough! 🙂
Thanks man keep doing this great work
Just to note, if you are, like me, still operating on Mac OSX 10.6.8 and want to use xCode 4.0.2 or newer, you have to upgrade to 10.7 or better, which then means that your older software, like my Photoshop CS3, may no longer work. Instead, you’re stuck with xCode 3.2.6 if you don’t want to pay Apple $99 developer fee. This is why I will likely stick with HTML5 and JqueryMobile for now.
Hi Chris,
I am a newbie in all aspects of programming and developing application. I hope, if you are not so busy, you can reply to my messages in the future. I have not even began to read the posts but I have this feeling that I am definitely going to learn many things.
Thank you
Regards,
Joe
Hello Joe,
Thanks for reading and I’ll definitely respond to you here!
Chris
btw i wish you made a youtube video about this and show some examples so i can see what it is doing
I am working on it 🙂
i am only 16 and trying to learn coding but i have such a hard time understanding this :3 but i wont stop i will just read it a couple times more
Hello!
Please feel free to contact me in the orange box on the right-hand side if you have questions!
Thanks for reading!
Chris
Hello, when I go to my source file and type #import “Superhero.h” the source file is unable to find the Superhero file from the header. I typed in everything exactly as you had it and even checked my spelling, still not working! Can anyone help me with this?
Hey Paul, you can contact me through the orange box in the right-hand side bar of the site and show me your xcode project. I’ll see what’s going on.
Hey Chris , thanks for sharing your knowledge
my feedback : consider iam reading this at 5 am without sleeping , it may be the reason or not but i find the superman and ironman a bit confusing , i know you choosed that to make it easy for us but for me its still confusing , another thing is examples and illustartions with details and for each word of the programming jargon with a color or explantation near it to make really clear .
i repeat thank you so much
Hey Ahmed, thank you for this feedback! I agree.. i was using the superhero metaphors but i think i abandoned it half-way. I’ll get around to revising it! Thanks again
Hey Chris,
This is what im talking about, Your lessons is easy to understand to me compared to a lot of other tutorials on the web thanks a lot man, I’m getting this, and it’s exciting.
hi chris do you have a video version to this, please thanks great work
Chris,
I can’t thank you enough for the willingness and time you took to put all of this together. Your site and videos have been an amazing source of information. Learning from you has been a blessing. Keep it up!
Hey Chris,
Accidentally stumbled upon your site and really excited that I did. Started with this first post as I’m far from being a programmer. I have a question for you, I’m having trouble grasping some of the above and you’ve done a really good job in writing it out, is there anything I can do to absorb it better? It’s around the Methods that I begin to lose my grip, will it eventually make sense if I read the next few posts or should I completely understand this before moving on?
Regardless, thanks for writing such an awesome introduction to coding for iPhone.
Pat
Good job Chris. Found this very easy to read.
QQ – what text editor are you using for these examples?
Hi,
Thanks for the easy to follow tutorial.
It is a great find for me to further my knowledge!
A.
Even though I knew OOPS I thought to explore how do u explain things?
You really have a knack for explaining things.
Keep it up.
Great article for beginners. I have exp in Java/ J2EE / Flex and other technologies. I wanted to learn iOS development. I am referring your videos and articles.. Awesome work.
Chris,
I have read and been exposed to several tutorials, videos and concepts. I have built a few apps with basic ‘see-n-says.’ Your information allows me to understand what I am doing. This helps to create a solid foundation.
Thank You!
Chris,
Thanks for what you are doing.. That’s a lot of work you put into something so great for others. I am completely new to this but very interested. Will have to go through. Articles many more times but look forward to getting there. Thanks again
I have a very limited knowledge in Java and C++ and have been hoping to get in to Obj-C. Thanks for this! Very straightforward and concise!
Hey Chris..just started to dive into programming with no experience..cant wait to really dive in and get into your videos..you seem to be a great teacher so far..any tips for beginners? do you happen to have this info in a .pdf format..thanks alot Michael
Good stuff for my mind in this inspiring article! Really, it was a lot to absorb and I absorbed it with appetite. I like the analogy regarding stack and heap.
Thanks a lot, Chris!
Hi Chris,
Awesome article! Your analogies make things so much easier to understand. I’m a bit confused on where the asterisk goes (i.e. after NSString, or before the NSString variable name, or when to do which), but maybe I just need to do some more tinkering and reading. Thanks!
Hey Bernice! Thanks for reading!
When you’re declaring variables, it’ll be NSString *variablename.
When you’re specifying method parameters or return type, it’ll be (NSString *).
Such as:
(NSString *)methodname:(NSString *)param1;
Thanks for reading 🙂
Chris,
Your tutorial is awesome. Its pretty fun and easy to understand. Please continue. Looking forward for more demos. Thank you.
Hello Reshma, thanks for the kind words! I’ll be finishing the last post in this series in the upcoming week so please subscribe and stay tuned!
Great job Chris, keep it up!!!
Thanks for the support Psyco!
Hi Chris,
I really like what you did here. Great job, keep it up!
Just one thing, you declare _stamina as a private variable and Name as a property, but later in you example you use property stamina. I found that little confusing.
Looking forward to the rest of the series.
Hello 5o,
Thank you so much for your feedback! I’ve made this correction and you’ve just made it more clear for everyone reading after you! 🙂