Developing a native iOS app is easier than ever. The tools have improved and so has the language. And yet it can be daunting because of the extensive sdk with various APIs and then you have to learn a completely new language known as Objective-C. Most developers fear a new language because of all the nuances that go along with it. Well, fear not, in this post we will learn how to build a super simple iPhone app and find that it’s really not that scary.
Before we get started there are some tools of the trade that we will need.
- Mac OS X 10.7 or above
- Xcode 4.5 available for free from the Mac App store
Xcode is installed just like any other app on your Mac desktop under the Applications folder. So go ahead and open it up.
Your First App
The first time you open up Xcode you will see the following welcome screen. Click on “Create a new Xcode project”
Next you will be presented with a variety of templates to choose from. If you click on each template you will see a brief description of what that template is about. For now let’s go with “Single View Application”
The next screen presents us with some options.
- Product Name: the name of your application which in this case is simply HelloWorld.
- Company identifier: also known as a namespace to prevent apps with exactly the same name. Imagine if there was another app in the appstore called HelloWorld. That would create a problem hence we have the company identifier to differentiate from other apps. Common practise is to use your company’s website domain as the identifier, hence the reason for using com.teamtreehouse. But don’t worry if you don’t have one you can put anything you like. You can even put your own name. Or just leave it as com.company you can change it later.
- Bundle identifier: The Product name combined with the company identifier makes up the bundle identifier which will come in handy when you are deploying your app to a device or prepping it for the app store.
Leave the other settings as is and click next.
Xcode is neatly divided into three main areas out of which you can show or hide the Navigation and Utility areas using the View toggle to the upper right corner.
Since we selected the Single View Application template, Xcode generated a few files for us. Amongst which is something called a Storyboard. A Storyboard allows you to visually layout your views and view controllers. In addition, it establishes the connection between view controllers. Don’t worry if you don’t understand any of this yet. Click on the file named MainStoryboard.storyboard and you will notice something that resembles a blank view of an iOS app with a battery indicator to the top right. This is your view which is visible to the user of your app. To this view you can add many interactive or display controls such as: buttons, labels, switches, sliders, etc.
Let’s add a label to your view so we can display the words Hello World. You can locate the label control by using the search field to the bottom of the Utility area which is split in two. The bottom half of the Utility area lists an object library which displays all the controllers and controls available.
Drag the label onto the view.
Increase the width of the label by dragging the right edge of the label control and releasing it when you see the blue guides which ensures the label is centered and equidistant from both edges of the view.
Enter “Hello World” in the attributes inspector in the Utility area to the right.
Finally, either click on the Run button to the top left of Xcode or use the keyboard shortcut Command(⌘)+R and see it run in the iPhone Simulator!
Want more? Check out How to build a simple iPhone app