Building Your First App: The “HelloWorld” Tour of XCode

Tutorials

Video:

Introduction:
Ready to get started with Xcode? In this tutorial you’ll create your first app and in the process you’ll get a tour of Xcode and the iOS simulator so you have a good understanding of the tools you’ll be working with.

 Writing Your First Line of Code

So now that you know the basics of navigating around Xcode, let’s jump right in and get started writing your first program.

1. Open the “ViewController.m” file.

With the file open in the middle of Xcode, you want to find the spot that looks like this:

Xcode image of ViewController.m Selection

2. Inside the curly braces I want you to type the following line of code:

NSLog(@”I say Hello World!”);

Your file should now look like this:

Xcode Image of NSLog() Statement

This one line of code will actually do something. Want to see it work? No problem.

Running Your First Program

2. In the upper left-hand corner of Xcode click on the big button that looks like a Play button for a video.

Image of Xcode Build & Run Button

Xcode will start doing a lot of things and if all goes well, eventually a simulated iPhone should appear on the screen. When you install Xcode, Apple also installs this simulator so you can see what your apps will look like in an iPhone (or an iPad if you want). Our simple app doesn’t have any graphical design to it, so the iPhone will have a blank screen.

Checking Program Output in the Debug Area

To see the result of our one line of code, you need to switch back to Xcode and look at the Debug Area. The panel should be visible, but if not click on the button to display that panel that is in the upper right-hand of Xcode.

Image of Xcode Output Console

You should see the following information in the panel.

Image of Xcode Output Console

There is a lot of apparent gibberish in there, but what you’re really interested in is the line indicated by the arrow.

Notice that whatever you put inside the NSLog() command in your program is what will be displayed in the output panel when you run your program. NSLog() is a simple statement that we will use to make sure our programs are running correctly.

Congratulations! You’ve completed the HelloWorld exercise. You’ve now written your first computer program and tested it in a simulated iPhone. You’re on your way to creating great apps.

Related Resources

Learn it all.

 

Julian Bryant


Related Posts

Objective C: Saving User Preferences

iOS App Starts Trounce Android Development

iOS App Starts Trounce Android Development

Image of Pop-up Window for Setting Properties

Quick Tip: Shortcut for setting @property/@synthesize in Xcode

Mobile Developers Excited About iCloud & Google+

Nav Bar 3: Using Custom Images in the Nav Bar for iOS

Nav Bar 3: Using Custom Images in the Nav Bar for iOS

Nav Bar 2: Customizing the Navigation Bar in iOS

Nav Bar 2: Customizing the Navigation Bar in iOS