Updated Oct 3 2013: This tutorial is compatible with XCode 5 AND XCode 4!
We’re taking a practical approach to learning iOS programming. This means lots of hands on work and practice!
In order to benefit the most from these lessons, you should open XCode and try to follow along.
This is part 3 of the lesson plan. Click here for the entire Learning Plan.
At a glance, your the new blank XCode project you created from the last tutorial has the following files:
Main.Storyboard (may not be named the same in XCode 4)
Notice how you have an AppDelegate.h as well as another one with a “.m” extension.
The .h is called the Header file and the .m is called the Implementation file.
Together, they form the AppDelegate class.
Wikipedia describes a class as:
In object-oriented programming, a class is a construct that is used to define a distinct type. The class is instantiated into instances of itself – referred to as class instances, class objects, instance objects or simply objects.
You can think of a class as a blueprint for something. Just like a blueprint for a building.
Using that single blueprint, you can create multiple instances of that building.
Similar to that, When we program iOS apps, we create and define classes to represent different entities and then we use those classes to create instances of that entity. We call these instances objects.
Now you can visualize the files in your Xcode project like this:
Your default Xcode project creates two classes for you; One called AppDelegate and another one called ViewController.
So what is Main.storyboard?
It turns out that the ViewController class is exactly what it sounds like. It’s a class that is responsible for controlling and managing a View!
So Main.storyboard is naturally the view that the ViewController class is managing!
To be more specific, the Storyboard describes the views and app flow.
If you click on Main.storyboard, you’ll notice that the main editor area of Xcode changes into a visual designer for that view. This is known as “Interface Builder” and you will be using it very soon so contain your excitement for a moment and let’s continue going through these files!
Now that you understand that you have two classes and a view, let’s see how they all relate to each other.
Your Default iPhone App Flow
Here’s a simplified visual diagram of what’s happening in your default Xcode project.
Looking at the diagram above, notice that the AppDelegate object is the entry point to your application.
Then the AppDelegate is responsible for creating a ViewController object when it notices that your app has launched.
The ViewController object is responsible for setting up the view described in Main.storyboard and showing it on the screen to the user.
And that simple app flow is how you get this!
Where Do Objects Live?
When you write code to create an object, it gets created in memory.
Think of memory as an abstract space to store and keep track of all of your objects.
The memory space is not persistent; meaning that if your app is stopped, then everything in memory is flushed and you’ll lose all of that data.
Furthermore, your app on the iPhone or iPad is only allotted a certain amount of memory.
So that means if you continue to create objects without removing the objects that you don’t need anymore, you’ll eventually run out of space in memory and your iPhone app may crash.
A long time ago, programmers would need to manage this on their own and release objects from memory when it was no longer needed but these days you can use Automatic Reference Counting which will automatically remove unused objects from memory for you! (Remember when we created our Xcode project and we had “Use Automatic Reference Counting” selected?)
That’s a good place to end for this tutorial. If you’re new to programming, this concept of classes and instances of classes being objects is enough to wrap your head around but it’s a very critical part to understand!
If I can elaborate on it more to help you understand, please don’t hesitate to comment below and I’ll update the FAQ section on this page to benefit everyone.
Click here to go to the next lesson now!
Frequently Asked Questions
There are none right now but if you have a question related to this tutorial, please ask below and I’ll update this section!
hey chris is there a way that you can add another app delegate .h, .m with adding files to app .thank for the help
Hey Abfaiez, you wouldn’t add another app delegate, but you can add a new class (.h/.m) to your project.
You can check out how here: https://stackoverflow.com/questions/26009639/xcode-6-creating-new-objective-c-class
Hello Chris I’m very happy that I have the opportunity to learn how to build an app to iPhone.
I have tried to learn it through books, but when I don’t have any programming background it is too difficult for me.
The only thing I have achieved is there are many projects in my Xcode.
How do I get rid from them? So I start anew with you?
Hey Aldo, just start a new project and follow along! 🙂
hey chris thanks for such a detailed explanation i an not from a programming background but with your videos and notes i am exited that how fast i can learn
Hey chris, i want to develop an app and it doesn’t seem as easy as i thought. Around how long will it take to create an app?
I think someone is wrong. When I try to test the app, without doing anything to the code or whatever, instead of showing the screen like it does in your video, it’s a black window. In other words, the iOS simulator doesn’t work. It goes black, then flashes some apps on a screen, then goes white. Thanks for this course!
There’s a couple things you can try, first try resetting your iOS simulator. In the menu there’s a “reset content and settings” item where you can reset it. That fixes some simulator problems.
Another thing to check: when you screen goes black, flip back to your Xcode project, do you see a green line highlighting a line of code? If so, that could be a crash. If this is the case, let me know what the detailed error message is using this tutorial and i’d be more than happy to help you figure out what’s wrong! https://codewithchris.com/xcode-errors/#detailederror
I see that the AppDelegate creates objects for the ViewController, and the ViewController sends it to the iPhone screen (the Main.storyboard).
What is the point of the ViewController then? Can’t Xcode just send stuff from the AppDelegate to the Main.storyboard without the use of the ViewController?
Or does the AppDelegate create the object, and the ViewController translates it so it can be sent to the Main.storyboard?
Thanks again Chris!
Hello! They all serve different responsibilities so they’re all crucial to working together to make things work. The app delegate responds to system events like when the app is launched or sent to the background and gives you a chance to write some code responding to those events. Each ViewController is responsible for it’s own view.. the storyboard actually can contain multiple views for multiple view controllers.
It’s simply the way Apple designed it to work! 🙂
great video, i look forward to continuing my path to becoming an ios developer at age 10
Hi Chris, so for so good.
Hi i was amazed by the WWDC yesterday from Apple and sparked my interest in developing apps. I think this a great thing you have here, I feel like I can master app making in no time. But for a heads up for you, when I was going through the begining parts of your tutorial I was lost when you said to make sure “automatic reference counting” was yes, I had no clue where to find it along with storyboard. Thanks for this awesome tutorial and keep up the good work. Also are you going to put out a supporting tutorial for swift and will that be included in $67.
Hey Saul, thanks for your honesty! I suspect you’re using Xcode 5 in which case you won’t even see that checkbox to turn on automatic reference counting. It’s on by default.
I’ll definitely be updating the course to use Swift when it’s out but i might be changing the pricing structure soon!
Hey Tienny, just treat your Main.Storyboard as the same!
Hi.. i lik to devolop new apps in iphone ..and till nw i hav only knw basics in c..and i am also a beginner for this..can u say whts the max days it will take to devolop??
hello chris , i don’t have any background in objective-c, but i took c++ as a course in university do you advise me with a particular book will help me i am a beginner, i started learning how to develop iphone application by you – thanks for great help-
the question do u advice me with some books -or- follow your 9 step ? and after that where i will be any continue after i finish these steps ?
Hey Abdallah, if you’re looking for a book, search for the big nerd ranch iOS programming book (it is a bit dated and using iOS6 but it explains stuff well). After step 9, I would recommend that you check out my video course! https://codewithchris.com/beginnercourse/
Hi Chris and Abdallah, we’ve updated both our iOS and Objective-C guides for iOS 7 and Xcode 5. Sounds like beginning with the Obj-C book might be a good first step.
That’s awesome Tasha, thanks for chiming in!
Hi Chris, thanks for the time spend creating these videos. I am using 2 MacBooks to teach me using your videos, 1 to watch and learn and the other to actual perform and hands on task following what you are doing on the video, however there is a difference on your screen and my screen.. you have a file called viewcontroller.xib and I do not have that file on my screen, I have Main.storyboard and you do not have it on yours.. Why is this????
Hey Laurence, thanks for following along! It’s because I need to update the video for Xcode 5 this week 🙂
For all intents and purposes, you can treat your Main.Storyboard the same exact way. You should be able to follow everything I’m doing even though mine is .XIB.
On a side note, i have updated the text versions so you should see Main.Storyboard referenced there. It’s just the videos that i have to get to updating this week.
The tutorial is extremely useful one question I have is when declaring methods what file should the decleration go in and which file should the code that creates something/carries out a transformation go?
Many Thanks in advance
The declaration should go in the header file (.H) and the code that carries out the function should go in the implementation file (.M).
such a wonderful tutorial, thank you so much for your efforts Chris!
any idea why my simulator is so big and dosent fit into one screen? like its really bug and is just a blank screen with no iphone surrounds like its just the screen if you know what i mean ?
i mean my iphone emulator , when i run the app it is very slow and also has no iphone surround such as the home button etc
Hey Tuhin, you can actually hit Command+1, Command+2 or Command+3 to change the zoom level!
What are entities? 🙂
Hey Rose, by “entities” i just meant any real world “thing”. For example, if you had an app that displays news articles in a list, you might create a class to represent the news article. (read this tutorial to see if it helps: https://codewithchris.com/learn-programming/)
Hello , i was just wondering if you ever updated the the videos with annotations for Xcode version 5
Nevermind, I just figured it out. Sorry
Hey Wilfredo, yup! did you have to turn them on or something?
I’m curious because others have asked and I often thought “are they unable to see the annotations or something?”
Well the notes you have on here explain it a bit better for Xcode version 5. But in the videos I don’t see them. So , I watch the video first to get a general idea of how to do the lesson and then I read and work off the notes for Xcode version 5. I really appreciate you doing these lesson for us. I absolutely know nothing about programming and coding, I like the pace of the lessons and I like how you take your time to answer everyone’s questions. Thank you
No problem, thanks for sharing your experience and thanks for enjoying!
im also facing the same as Wilfredo does
..and Thanks so much Chris for this hard work ,really i appreciate it .:D
FYI, I am able to see the annotations you’ve made in the videos for Xcode 5 : )
what’s in it for you, apart from the obvious satisfaction of doing something good and doing it right? 🙂
Hello! Do you mean why I’m doing these lessons for free?
This whole website/tuition thing… It’s really very good, but does it pay any bills for you? I hope it somehow does! If I ever get rich from any of my apps, I’ll buy you a Ferrari 458 Italia!
He’s also selling a tutorial videos section. He might be making money for ads or affiliate links, and is strengthening his brand by adding free content. Maybe he actually also cares about teaching people. And it’s not all about the money. 🙂
You’re the man. I’ve only watched a few of the videos thus far, but have been really impressed with the thoroughness and clarity in your instruction style. Please keep it up. I’m looking forward to seeing how much I can learn and how fast.
Thanks for reading and taking the time to leave a comment! Glad to have you and please let me know if you have any questions.
I was a teacher for 36 years and in classes at several graduate schools. Your delivery, knowledge, and pace made this one of the best lessons I’ve heard.
Hello Gerald, that’s probably the best compliment I could receive! Thanks for the compliment and encouraging me to get better at teaching; it’s definitely an art.
Really good tutorial and very well explained, Im goin to read through it a few times and watch the video again just so i really grasp the fundamentals of the lesson. Well done on your explanations!
Thanks Stephen, let me know if anything is unclear and i’d be happy to explain. Thanks for watching!
I wanted to say thank you so much Chris for these videos. You make it real easy for a guy like me who has been out of the programming realm for the last 13 years. Thank you for taking the time to make this. I am right now reviewing the basics before I jump into the heavy stuff. Thank you again.
Hello Jon, thanks for taking the time out to comment! I really appreciate your message and I’m sure you’ll pick it up really quickly. Let me know if you run into any questions!
Very nice video masallah I will share and ads in your site 🙂
Thank you for your support! 🙂
Thank you so much for the valuable videos, if you don’t mind can I use them in my IT class. I want to introduce xcode to the students and learn it myself at the same time. Your videos are awesome and so simple to follow. thanks again
Of course you can use them in your IT class! It would be awesome if you could tell the students to visit my site 🙂
i have them all hooked on your site, ps keep upmthe good work, you are awesome.
Thank you so much Liz. I’m so happy to hear that 🙂
Hi Chris, I’m new to coding as in RAW!!! Thanks for your work, even though i’m learning the jargon your process is easy to follow and helps me keep on track vs being overwhelmed by the amount of learning that is required to become a coder! Cheers
Thanks for reading, Angus! I’m glad you’re enjoying the articles!
When I make a new file in Xcode like on your videos, I am not getting the viewcontroller.xib file, but have all rest. What would be preventing that file to not show up? I have xcode version 5. I am not sure how to do the label part of the video series not having this file. Have any suggestions?
I appreciate your help 🙂
Hey Jason, I’m in the process of updating these articles for XCode 5. I should be done by Friday and I’ll follow up with you then!
Thank you for reading and following along!
I HAVE THE SAME PROBLEM? ANY IDEA WHY IT DOESN’T WORK?
I updated the video with annotations for Xcode 5 where things might be different. If you’re running Xcode 5 can you verify that you can see the annotations?
when you will download the video, can you be quick please
and thanx for the other videos
Hello! I’ll be uploading another one today, thanks for watching and please share it with your friends!
The next video has just been released 🙂 Come back to this article post to see it!