Your XCode Project Files Explained (and object oriented programming concepts)

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.

Class Files

At a glance, your the new blank XCode project you created from the last tutorial has the following files:

AppDelegate.h
AppDelegate.m

ViewController.h
ViewController.m

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 xcode project classes

Your default Xcode project creates two classes for you; One called AppDelegate and another one called ViewController.

So what is Main.storyboard?

Storyboards Explained

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.

your xcode project app flow

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!

66 Comments

  1. 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?

    Reply
  2. 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

    Reply
  3. 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?

    Reply
  4. 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!

    Reply
    • Hey Undergroundman,

      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

      Reply
  5. Quick question,

    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!

    Reply
    • 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! πŸ™‚

      Reply
  6. 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.

    Reply
    • 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!

      Reply
  7. 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??

    Reply
  8. 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 ?
    thank you

    Reply
  9. 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????

    Reply
    • 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.

      Thanks!
      Chris

      Reply
  10. Hi Chris,

    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

    Reply
  11. 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 ?

    Reply
        • 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

          Reply
      • 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!

        Reply
    • 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. πŸ™‚

      Reply
  12. Chris –

    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.

    Best,
    Matt

    Reply
  13. 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.

    Reply
    • 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.

      Reply
  14. 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!

    Reply
  15. 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.

    Reply
    • 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!

      Reply
  16. 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

    Reply
  17. 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

    Reply
  18. Hi Chris,

    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 πŸ™‚

    Reply

Leave a Reply to n163126 Cancel reply

45 Shares
Share
Tweet
Pin
Share
Buffer