Skip to content
Physics and Astronomy
Home Our Teaching Resources C programming xcode.html
Back to top

Tips for using XCode on the Macs

Running XCode for the first time

NB: Charles Williams has produced helpful video demonstrating the process, this is best run sitting at the Mac after reading these notes.

  1. From Finder choose: Window -> Applications
  2. Find XCode at the bottom and open it.
  3. When the XCode icon appears in the Dock click on it, hold down the mouse, then select "Keep in Dock".

    When returning to a project, open XCode from your dock and choose File -> Recent

Creating a project

  1. Start up XCode if it not already running.
  2. Choose: File -> New Project (or just click on "Create a new XCode project").
  3. Make sure the "User templates" box at the top left s selected (blue),and if not click on it.
  4. Select Exeter Physics Project then Next
  5. Choose a sensible name
  6. Your program text is in the file "main.c", double-click to edit it. Do not User Word, etc to edit your text file!
  7. When you come to print your program, print directly from within XCode, don't copy and paste into Microsoft Word!

Seeing the output (console)

Before running your program for the first time, go to the Run menu and choose Run -> Console (or Command-R). This brings up a window with your progam's output.

You should be able to make this happen automatically from the XCode menu:

XCode -> Preferences -> Debugging -> On Start -> Show console ->

Running your program

When you want to run your code click "Build and Run".

Note:To insert a hash sign (#) type Alt-3 (i.e. press and hold down the "Alt" key and press "3", just like using the shift key). Also notice that it's the "Alt" key, not the "Apple" key.

Errors and warnings

When you compile the system may flag up two types of problems: errors and warnings.

Errors

Errors are indicated by Red circles and denote code that is not valid C. The program will not compile or run.

Warnings

Warnings are indicated by Amber triangles. Technically, this code is valid and system will compile and run it. But it probably means you have made a mistake so fix it.

Seeing what they are

Error and warning alerts appear in two places: in the left-hand margin by the side of the individual lines with problems and at the bottom right of the window. To view all errors and warnings at once, click on the red circle or amber triangle at the bottom right of the page.

To view an individual error or warning, move your mouse over the relevant warning sign at the left of the code line and wait a couple of seconds.

Fixing them

In general, fix problems starting with the first one as this may also fix later problems.

One of the most potentially confusing errors is "Parse error" (or"Syntax error")which means you have made a mistake in your punctuation. It will tell you the character ("token") that it saw when it was expecting to see something else.

                                                                                                                                                                                                                                                                       

Validate   Link-check © Copyright & disclaimer Privacy & cookies Share
Back to top