O'Reilly logo

Beginning Mac OS® X Programming by Drew McCormack, Michael Trent

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

3.3. Writing Your Code

Most of your time in Xcode will be spent reading and writing the source files that make up your program. Xcode's source code editor has a number of features to make this time as productive as possible. Some of these features are passive, such as drawing different parts of your source code in different colors or styles. This helps you quickly recognize elements of your program at a glance. Other features are active, such as providing commands for quickly formatting large areas of code.

In the following example you write a small C program called Calculator that lets you add and subtract numbers. The program consists of two functions: the main function, which interacts with the user using Mac OS X's command-line interface, and a calculate function that does some arithmetic. The calculate function takes two numbers and an operator and returns the result of applying the operator to the numbers. If you aren't familiar with the C programming language, don't worry too much about what the code is doing; this is really just a chance to get used to Xcode's text editor. Alternatively, you can skip ahead to Chapter 6 where you learn about writing programs in C.

3.3.1.

3.3.1.1. Try It Out: Working in the Code Editor
  1. Choose XcodePreferences. Xcode's Preferences window appears.

  2. If necessary, select the General preference pane.

  3. Check the Open Counterparts In Same Window button. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required