You asked
What is the purpose of compiling sources in Xcode?
The goal is to tell the compiler which source files (e.g. .m files) should be compiled during the creation of the target.
A few practical examples of when you can edit your Compilation Sources:
In addition to the Idles example of including or excluding sources for several purposes in your project, another real scenario in which you could exclude sources from "Compilation Sources" is when you use a third-party library (for example, or a set of classes) that provides the source code, but you want to control which sources will be compiled in your project.
For example, if you use FMDB , you copy the sources to your project, but include the fmdb.m sample, which illustrates how to use FMDB, but you do not want to compile this as part of your application. You can (you might even want to) completely remove fmdb.m from your project, but you can also just delete this file from your compilation sources, so you have a good example of how to use classes at your fingertips, but that’s not will compile as part of your project.
Another example in the real world is if you use the SDWebImage infrastructure and include sources in your project. You may, however, not need the MKAnnotationView+WebCache , in which case you will probably want to remove it from your “compilation sources” if you do not use the maps and the MKAnnotationView class. If you saved this in your project, you may get linker warnings if you hadn’t linked your project with MapKit.framework. If you are not using MapKit, it would be easier to just remove MKAnnotationView+WebCache from your compilation sources, and MapKit.framework will need to be linked (when you don't need it).
Another time, you'll use Compilation Sources when you want to set the compiler flag only for a specific source file. For example, if you have an ARC project, but you have code other than ARC. You can go to Compile Sources, select the non-ARC.m file, and set the -fno-objc-arc flag, as described in Going to ARC Release Notes .
If you ever added files to your project, but accidentally neglected the “Add to Target” option, these source files would not be collected when creating your target. But you can go to Compile Sources and add these source files to the list of files that will be compiled, and later they will be included in future builds of your goal.
You asked:
Do you need every file in your project?
No, only every source file (e.g. .m file) that you want to compile. Not headlines. Not assets. Just the source code you want to compile.
If I add files to the project, is each file added to compile the sources?
If you select the “Add to target” checkbox when adding files, .m files will be added to “Compile sources” and resources will be added to “Copy package resources”, etc. Otherwise they will not.

source share