Your First iOS App: 100% Programmatically

Part 1

Austin Louden
Nov 30, 2013 · 4 min read

This tutorial is for Xcode 4.6, and was written in 2013. Check out my updated version (in Swift!), using Xcode 7.3/iOS 9.3.

This is Part 1 of a tutorial that follows Apple’s old “Your First iOS App” tutorial, but implements all of the user interface elements programmatically. View Part 2 here or view the complete code on Github. Discussion on Hacker News.

I created this tutorial for developers transitioning to iOS that don’t want to deal with Storyboarding or Interface Builder. It implements the “Hello World” app from Apple’s documentation entirely in code.

From Apple’s documentation:

When you run the finished app, you click inside the text field to reveal the system-provided keyboard. After you use the keyboard to type your name, you dismiss it (by clicking its Done key) and then you click the Hello button to see the string “Hello, Your Name!“ in the label between the text field and the button.

First, open Xcode and click on “Create a new Xcode project” I’m using version 4.6.

Use an empty application.

Fill out the remaining fields. Make sure “Use Automatic Reference Counting” (this is now enabled by default in XCode 5) and “Include Unit Tests” are checked. Core Data isn’t necessary for this tutorial.

Even though we chose to create an “Empty Application”, Xcode still created some default files. Navigate to the AppDelegate.m file by clicking the file browser on the left side of the screen.

The App Delegate file is your application’s way of communicating with the operating system, and includes several useful methods.

We’ll mostly be dealing with “application didFinishLaunchingWithOptions”, which is called immediately after the application launches.

If you click on the Run button in the top left, your application should build with a blank white screen.

You might have noticed a warning:

“Application windows are expected to have a root view controller at the end of application launch”.

Don’t worry, we’ll set this next, but first we have to create a ViewController class. Click on File, New, File…

In the Cocoa Touch section, select Objective-C class and click Next.

You can choose the name of your class, but make sure to set it as a subclass of UIViewController below. I named mine “MainViewController”. The UIViewController is a fundamental class of iOS development, and is used to make and handle interaction with elements in the user interface. Click Next, and then Create.

You should now have MainViewController.m and MainViewController.h files with some boilerplate code inside. We’ll come back to those in a bit — for now, go back to your AppDelegate.m file.

First, make sure to import your MainViewController class at the top of the file:

Next, take a look at the “application didFinishLaunching” method — it should contain some default code matching the one below:

It’s here that we set the “root view controller” property — or the view that is displayed when the application launches.

Running the app again should still give you a white screen, but this time the warning will disappear. In the next part of this tutorial, we’ll handle all of the on-screen elements.

Continue to Part 2

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store