CSCI 240
Using the XCode Development Environment


The program can be downloaded at:

https://developer.apple.com/xcode/

Download version 4.5.2 or the version that is recommended for the operating system that you're running. Note: You're probably going to have to create a free ADC membership in order to download XCode.

  1. Start XCode.

  2. Choose "Create a new XCode project".

  3. Click on the main.cpp file name to open it. Once it opens, it will probably have some C++ code that was generated by XCode. You can either delete this or modify it with your own C++ source code:

  4. /***************************************************************
    CSCI 240         Program 0     Spring 2023
    
    Programmer:
    
    Section:
    
    Date Due:
    
    Purpose: Compiler training
    ***************************************************************/
    
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
    cout << "hello, world";
    
    return 0;
    }
  5. Save the file. Use File/Save.

  6. Notice that some of the words in your program are in color. For example, the purple and pink words are C++ reserved words that have special meanings.

  7. Now compile and run the program by clicking on the Run arrow in the upper left corner. If the code does not contain any compile/syntax errors, you will see a "Build Succeeded" message. If the "Build Failed" message shows up, you have a compile error on the line that is highlighted. You must find and fix all such errors, and re-run until you get the "Build Succeeded" message.

  8. Once you have the "Build Succeeded" message, the program will automatically run and any output that is produced by the program will show up in the "All Output" box below the source code.

    Depending on the nature of your program, you may see a prompt for user input (which you provide by clicking in the All Output box and entering a value by typing on the keyboard) or some output displayed in the window. If you typed the program listed above, you will see "hello, world"

  9. Congratulations. You have created and run your first C++ program.

  10. Sit back and relax for 15 seconds... now let's go on.

  11. Now, just to see what will happen, let's make a couple of mistakes on purpose. Use the delete key to erase the closing " (double quote character) after the word world in your program. Now try to run it. Notice that the code has been highlighted with 2 errors. This is common - one mistake may cause several error messages. Your usual response will be to try to fix the first error in your program (which is usually indicated by the first or first few messages) and re-run. In this case, the error mentions "missing terminating " character".

  12. Now try deleting the semicolon at the end of the same line. Run the program. You should see the same error messages even though we know there are now two errors. This often happens: one error "hides" another. Restore the " but leave the ; missing. Re-run. Now you see the message "Expected ';' after expression'".

  13. Restore the ; and change the character string to: "\nhello, world" That's a backslash before the n. Run the program. Notice there is now a blank line at the top of the DOS screen. The sequence "\n" makes the cursor on the output screen go down one line. (Try it again using a forward slash to see what will happen.)

  14. Misspell the word main. Make it "maain". Run. The "Build Failed" message should show up but no code was highlighted. This is because the error was not a compile/syntax error, it was a linker error. Click on the Issue Navigator (the little triangle with the exclamation point) to see the linker errors. Read them. This illustrates that some error messages are not entirely clear.

  15. Fix the program, compile and run it again.

  16. (Almost) finally, before you leave, save the program. You will normally want to make a backup (a separate) copy of your work in case the the original is lost due to equipment failure (it could happen) or some mistake on your part (also could happen).

  17. Choose File/Close Project to quit your XCode session and close XCode. You can then do other work on the computer. First, though, pretend you have come back (another day maybe) to continue on working your program.

  18. Start XCode again. Your recent projects should appear in the Recents box. Select the project and click open. In the main.cpp file, add another line after the first cout line but before the return line:

  19. cout << "\ngoodbye for now..";

    Run, check it, save, and quit.

    That's enough for one day....Except

    One final note, when the project was created, it was placed in a folder wherever you specified in Step 2. The folder will be named whatever you supplied for Product Name. For the above example, the folder should be named Hello.

    Inside of the Hello folder will be two items: another Hello folder and the file Hello.xcodeproject

    Inside of the second Hello folder, there should be 2 files: main.cpp and Hello.1. The main.cpp file is the one that you will submit when turning in assignments.