Introduction to Xcode

Author: Mark Szymczyk

Last Update: October 6, 2005

This article walks you through your first Xcode project. You will learn how to create a project, edit source code, and build your project into a working program.

Creating the Project

The first step you must take to use Xcode is to create a project. A project contains all the files needed to create a working program. Choose File > New Project to create a new project. A window opens with a list of project types you can create.


Choose a C++ Tool project, which is in the Command Line Utility section, and click the Next button. Tool projects create programs that do not have a graphical user interface. They are meant to be run from the command line using the Terminal application. Tool projects are simpler to write than regular Mac OS X applications, which is why I’m using a tool project.



Enter the name you want to give the project in the Project Name text field. I used the name MyFirstProject. Click the Choose button to choose a location to store your project. Click the Finish button. You’ve just created an Xcode project.


Editing Source Code

After creating the project, the project window opens. You should see a list of files in the center of the window. If you don’t see a list, select the name of the project from the Groups and Files list on the left side of the window. The project name should be the first entry in the list.



The file main.cpp contains the source code for the project. Double-click main.cpp to open it in an editor window. The editor window is where you write the source code for your applications. You should see the following line of code:

std::cout << “Hello, World!\n”;

Change this line to the following:

std::cout << “This is my first Xcode project.\n”;

Save the file.

Building the Project

Now it’s time to build a working program from the code we wrote. Xcode calls the process building. When Xcode builds your project, it compiles the source code files in your project and links any frameworks and libraries included in the project to create an application. Our project is very simple with no frameworks to link, which makes building the project easy.

Choose Build > Build and Run. Xcode will build the project and open the run log. The run log is where you can see the project’s output. If you look at the run log, it should say This is my first Xcode project. Click the Run button in the run log toolbar to run the program again.



Conclusion

Let’s review what you’ve learned. You learned how to create a project, open an editor window, edit source code, build your project, and run your program. At this stage you’re ready to read a programming book and work through the examples in the book. Create a new project for each example.

I used a C++ Tool project for this article, but Xcode provides tool projects for other languages. Use a Standard Tool project to learn C, a Java Tool project to learn Java, and a Foundation Tool project to learn Objective C.