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.
Whether you’re learning iOS development, Java or any programming language for that matter, there are core computer programming concepts that are central to learning how to program. That’s what we’re going to go through today.
In this programming primer, we’re going to start at the very beginning and assume that you are not a programmer and don’t have any knowledge of computer programming. The concepts introduced in this tutorial will help you absorb the subsequent Objective-C and iPhone programming tutorials with a better understand of what’s going on.
We’re going to introduce the following object oriented programming concepts which many programming languages use (including Objective C).
1. Programming is like…
5. Class Inheritance
7. Another Example
8. What’s Next?
1. Programming is like…
It may be odd to think of it this way, but programming is much like designing something.
Think of an application as a stage play and you’re the playwright, otherwise known as the person who writes the play.
Let’s make it concrete; let’s say that you’re Shakespeare and you’re writing an app called Romeo & Juliet.
Before you can choose an actor and actress to play the roles, you have to define what the roles are first, right?
Well, when you’re building an app, you do this by creating classes.
We said above that classes are like descriptions of roles in a play.
It describes how something will behave and act as well as its characteristics.
In our Shakespeare metaphor, we might define two classes: a Romeo class and a Juliet class.
These two classes will describe the roles that we need in our play. Within each class, we’ll need to store bits of information about each role so we use something called variables.
A variable in programming is used to store or point to data.
With our Romeo and Juliet classes, we might define variables in each class such as hair color, eye color, height and so on. These variables in the Romeo class can then store the data for Romeo’s hair color, eye color and height. And similarly, we’ll define the same variables in the Juliet class to store Juliet’s hair color, eye color and height.
Next, our classes also need to describe the actions that these roles will take, similar to a script.
There are lines that Romeo needs to say and actions that Romeo needs to perform. Likewise for Juliet.
We define these instructions in each class by using methods.
A method in a class is like a set of instructions that can be called upon to perform those instructions. Each method has a name and the name simply has to be called upon and the instructions inside the method will be executed.
So in our Romeo and Juliet example, the tragic final scene of the play has Romeo believing that Juliet has passed and so he ends his own life.
So as unfortunate as it is, we could create a method called “endLife” in the Romeo class so that when this method is called, Romeo will take his own life 🙁
5. Class Inheritance
Class inheritance is a way for you to define a class that is based on another class.
The class that is being inherited from is known as the parent or super class and the new class that is doing the inheriting is called the child or subclass.
In our Shakespearean example, there are particular variables that both the Romeo class and the Juliet class share in common. Namely, hair color, eye color and height.
Instead of defining these same 3 variables in both classes, we can create a brand new class called “Person” and define these 3 variables in the Person class.
Then we specify that Romeo inherits from the Person class. In other words, Romeo is a subclass of Person. And Juliet is also a subclass of the Person class.
Now, both the Romeo and Juliet class will also have the 3 variables. The same can be done for methods.
If there’s a method that both classes should have, we can define it in the Person class instead. Say, for example, a “Kiss” method.
However, for the “endLife” method, only Romeo should have that method, so we define the “endLife” method in the Romeo class instead of the Person class.
Now that we have our roles defined, we can finally hire an actor to play Romeo and an actress to play Juliet.
Well in programming, once we have our classes defined, we can create an instance of that class called an object.
So we can create a Romeo object from the Romeo class and a Juliet object from the Juliet class. It’s these two objects that will interact with each other.
Just like an actor and actress will bring the roles to life, creating an object from the class is bringing that class to life and it will behave exactly like you’ve defined it. It will have the variables you gave it and the functionality that you defined using methods.
The only difference between creating objects and hiring actors/actresses is that with programming, you can create multiple objects from the same class. So you can create two Romeo objects from the class and you can set the hair color of Romeo object #1 to yellow and the hair color variable of Romeo object #2 to brown.
That will make for an interesting Romeo & Juliet play!
7. Another Example
Another way to think of defining a class is like defining a blueprint for a robot.
The blueprint describes the robot’s properties and how it behaves and acts with other robots.
For example, we might define the classes below for an application that fetches some data and displays it to the user on the screen.
During the execution of the application, instances (objects) of each class may be created and then their methods carried out to generate the desired result.
Remember, a variable is used to keep track of a piece of data.
When we define variables in classes, we are usually defining them to keep track of information that is vital to that class.
Because variables are defined as part of a class, all objects of the class will have that variable.
In the example above, we might define a variable in the DataBot class to hold on to the data that it has fetched. Let’s call that variable “robotPocket” (as if robots store data in their pockets!!)
If we create an DataBot object, it’ll have this variable “robotPocket” but it’ll be empty initially.
After our DataBot object fetches the data, we’ll store it in the “robotPocket” variable which will later be passed onto ControllerBot.
Similarly, ControllerBot will need a variable to hold the data that it gets from DataBot.
And ViewBot will need a variable to hold the data that it gets from ControllerBot.
Next, we have to define the methods in the class and fill each method with instructions that may involve retrieving values from variables, assigning values to variables, calling other methods of the same object or even calling methods of other objects.
In DataBot, we could define a method called “getData” which would contain the instructions for DataBot to get the data we need to display to the user.
8. What’s Next?
Hopefully these analogies haven’t made things even more confusing for you! As a beginner trying to learn to program, these programming concepts may be hard to grasp at first but once it clicks, it’s going to become second nature to think this way.
Now that you’ve got some notion of what classes, variables, methods and inheritance are you can proceed to the first article in the How To Make iPhone Apps Crash Course!
Go To Part 1
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!
if i make an app for the windows store will i be able to have my app be downloadable within many other stores as well such as the app store and google play?
Unfortunately not! You’ll have to build the app using different programming languages and tools for each store!
very helpfull article
Seriously awesome, man. I am planning on following this series closely. Thank you for taking the time out of your life to share your wealth of knowledge with beginners like me!!!
Im 12 years old, and this article just opened my eyes. Thanks article maker.
Hey Chris, I see this is an old article, but I hope you still seem to help inviduals. So i’ve been reading and my problem is i often do not understand until i actually try, so I thought to ask, how to try that theory, what application to use, on which system.
Thanks for the reply!
Two things: I think you did a fantastic job relating code to two different types of people. My background is in English Lit, so naturally Romeo and Juliet was easiest for me to comprehend. However, the robots provided great visuals for those who learn best through visual aids.
I like this….. lemme follow you on twitter or facebook.
i work in theater so i really enjoyed this analogy!
Finally an explanation that makes sense! Thanks!
Thanks, Chris, the actor analogy has really helped me begin to get a handle on this.
I LOVE THE WAY YOU EXPLAIN THIS CONCEPT THAN,YOU
This was awesome Chris. Thanks for making it. I (usually) don’t find learning programming interesting; both the R&J and Robots examples helped. I’m just hoping future lessons will be just as easy 🙂
So happy I found this site! Have a great idea for a business that needs an app and a little bit of programming knowledge from forever ago. You explain all this very well 🙂 thanks! hope to have my app within the next 6 months
I can develop app for you
I am taking a serious first step into learning how to program IOS. I am going to use your info and follow it to the letter. I will post my progress and finished design when I am done. Here goes day 1.
I guess I am trying to figure out if it is the version of Eclipse that is causing me to have these issues,my works pace has all the same headings but some of the other options are different.I believe that the text implementation may be different from version to version.Could be that the coding is different because it is not backwards compatible.That is to say what is on the video may be an older version than I am using.Thanks again,I will keep plugging away,have learned a few things but if I keep getting errors in the demos then trying to implement my ideas for a program is going to be difficult if not impossible.
I liked both. I’m a beginner. Sir? Did Juliette also take her own life in the story, if so does that mean they could share the endLife class? Yeah I was that kid.
Thanks Chris,that is exactly what I have ,trying to learn code is not all that difficult if you can follow it.Can you suggest a site with the video tutorials,I have gone to a few and what I have found so far is similar but not the same.I keep getting errors and the screen setup is somewhat different than what I have .For instance one site starts with relative frame and my program starts with frame layout so I have to wonder if that is an issue but the rest seems close.Another issue is the
It shows errors seems to want “@string/Hello World” and still errors ,if I do that my graphical view shows the @string/Hello World.
Trying very hard to get through this ,probably a good thing,it keeps me trying to work out errors but really slows the progress of learning.
Hey Larry, unfortunately i’m not really involved in the Android world so i don’t know any good sources. I wish i could help you with the errors but i don’t have any knowledge with Android development.
My only advice is to keep at it! It may be slow in the beginning but you’ll pick up speed!
Yes, I can confirm! I’m done reading a couple of books about iOS programming (aside of Chris’s video) and I’m now on my own facing Xcode…. time is long!
But, the key is to never give up, right!
Yes I too seem to understand the robot scenario,it makes a bit more sense to me .I have been in manufacturing automation but not really programming .Do I need a Mac to program an app that can be used in an Android or other phone platforms?
Hey Larry, thanks for the feedback! For Android apps, you can develop them with a PC but you need a Mac for iOS.
Thanks for the input,right now I am trying to get a handle on the programming,tutorials are a great source of teaching but I have a problem trying to follow along,I spend more time trying to figure out what is wrong in the code and I don’t know code.I believe I can grasp it but the software that I have is not the same as the video tutorials so that makes it pretty impossible to actually learn something when I cant get it to work right.The software I am using is:
It seems like you’re using Eclipse and Java which is the tooling for building Android apps. Try googling for some beginner Android tutorials and I’m sure it’ll be a lot easier to follow since they’ll be using the same tools/software!
Good job Chris. Very helpful and well explained. One comment; the first sentence in the Methods section could use a little adjusting. Thanks so much for your hard work! Looking forward to reading the rest.
Thanks for reading and letting me know about that error! Fixed!
Love it ! You have a great way of explaining – love both examples. Well written !
Hey Sandy, thanks for reading and leaving a comment!
I thought I only had to read one article, I visually learn. I forgot what the article was named.
I felt the robots were easiest and was confused with Romeo and Juliet. But so far so good!
I agree. I like the robot example!!!
Awesome article Chris! 🙂 thanks for sharing some of your knowledge about programming, and extremely well written. I agree with camilio, i find the play metaphor easier to understand, but i guess what works for your brain is different from person to person. I am interested in creating and app, if i want to make a simple game app how long do you think it will take me? im new to programming on the pc, but i am gonna invest a lot of time into programming if it stays as interesting as you write it right now 🙂 thx again Chris
Hey Simon! That’s great, programming is definitely something that can be learned!
However, to develop apps/games for iOS, you’re going to need a mac unfortunately. There ARE some PC solutions, but they involve using VMWare to emulate a mac or you can also “rent” a mac for a small monthly fee at macincloud.com.
To write a simple game, you could probably do it in a week if you follow a tutorial. You might not totally understand what you’re doing, but follow a couple more game tutorials and you’ll start understanding how it’s pieced together.
One thing i want to mention though is that building games is quite different from apps and unfortunately I don’t have much experience with games. For iOS games, you’ll want to look at something called Sprite Kit.
Thanks for reading!
I don’t have a game app. I have an app I’m creating that I don’t think is super complex but is definitely not typical mold. Would I still need a Mac?
Hello rbertou, you’d still need a Mac for any sort of iOS development!
Thank you for writing this. Could you possible put parallel instances of code along side or just under the bots/romeo ?
also, do you do private lessons? Really need a tutor to get started!
Hey Geoffrey, yup, you can spawn an additional “thread” of execution and have parallel threads doing stuff simultaneously.. i assume this is what you mean..
The closest thing i have to private lessons is my video course where I help you with your specific obstacles in learning! Check it out here: https://codewithchris.com/beginnercourse/
What is properties you mentioned in the example 2 actually means in the example 1? coz you did not mention about properties in the first example. As I know object is equal to instance, so what is properties?
very good article. I am a beginner and I understood it. If I were you I would have stick to the Romeo and Juliet example until the end, instead of adding the robots example. a Variable could be “what does it have in its hand?” or something. Anyway, very good, I will keep reading 🙂
Hey Camilo, thanks for reading 🙂
I’m glad it was easy to understand! I actually wrote this article originally using the robots example almost 6 months ago but never posted it! I changed it to Romeo and Juliet last night but i didn’t want to waste the diagrams i had created for the robots 🙁
I updated the robot example to use a variable called “robotPocket”. Thanks for the idea!
I’m still confused :/
I guess I’ll stick to playing video games and fantasizing about all the cool games that are never made and hope someone makes em :p
I don’t think I have computer programming blood in me.
Some video examples would be even better :p (I’m visual and hands on as opposed to reading).
Hi Chris! I’m learning a lot from your website.
But still confused when there are multiple classes that work for each other
Need more practice to build my own concepts.
Nice metaphor by the way lol
Sung, i know you’re going to get it by reading as much as you do.
You’re always the first person to comment!
It is tricky for first time programmers. I faced the first assignment and realized I was confused and came back here to grasp the concepts again. The relationship between classes and objects can be confusing, you need to understand the object to do a good job of defining the class and without an understanding of how classes are defined you will never create an object. Rather like, which comes first, the chicken or the egg? Great course.
Thanks…helped a bit to understand