Xcode How to Read From a File

The default settings in Xcode make it confusing to figure out where to put a datafile to be read by your program, such as dictionary.txt if you are doing some word comparison program. To do this you can either 1. Find the default location, or 2. Change the default location. These two approaches are explained below.

  1. Find the default location:

  2. You have to put your data files in just the right directory for your program to read them. Within Xcode select the "File Folder" icon near the upper-left of the window. Then select the "Products" folder, which should display the executable version of your program. Right-click on it, and select Show in Finder. The resulting directory is where to put your data files for Xcode to read.

  1. Change the default location:

  2. If you want to have your data files close to your source code, then this is the option for you. Note that this change affects all projects, not just the current project.

    1. While in Xcode, at the far upper-left of your screen select Xcode and then Preferences:

    1. Within Preferences select Locations and then Advanced:

      1. Within the Advanced window, under "Build Location" select Custom.

      2. Within Custom select "Relative to Workspace" in the dropdown menu.

      3. Enter values for Products and Intermediates. Putting a single period in the Products field will end up making a directory called DEBUG in the same location as your main.c file. Entering "Intermediates" in the field below it will also make a directory called "Intermediates" there.

        1. The executable version of your program will be in the DEBUG directory, which is where you should put your data files: