Tell Xcode Not to Compile a File

Editor’s Note: To read more about compile options and file date/time stamps, please head over to this post: Touch or Untouch a File in Xcode.

By default, when you create a new file or import a file into Xcode, if the file type is recognized as a source file (.c, .m .js, etc), the file is added to the Compile Sources folder in the application target.

You may not always prefer this default action – for example, if a JavaScript file is imported, Xcode does not know what to do with this file type so a compile warning is generated, see the example below:

I ran into this recently when I added a JavaScript file that is associated with an Openx ad that I wanted to displayed inside my application, using a UIWebView.

There is a simple fix, drag/drop the offending file(s) from the Compile Sources folder to the Copy Bundle Resources folder within the applications Target, which will simply include the file in the application bundle with no processing of the file (this is where you will typically see image files, sound files, etc).

In the image below, the file foo.js has been moved into the Copy Bundle Resources folder:

  1. This is great – thanks.

    I have the opposite problem!… do you force XCode to compile a file, even if it hasn’t changed?

    (I’m trying to create a project level build timestamp without going down the route of running XCode from a script).

  2. Awesome. Thanks. This was baffling me. I was renaming it to .txt to get around it. Not sure this is better as I will forget to do it the next time I create another target. But it works like a charm.

  3. Hi,

    Xcode do have the options touch/Untouch a file. These options also allow to do same , AFAIK.

    Not much sure, but I read some where of this kind.

    Please share on this whether its right or not.

    Thank you

  4. mpramodjain,

    Touch and untouch a file applies to whether or not on the next build a file should be compiled. However, if you were to do a clean of the project, which should touch all the files, all files would be compiled.

    The tip in this post marks a file as one that is never to be compiled, regardless of its date/time stamp.

    I added this post recently to provide a little more clarification to touching files: Touch and Untouch Files in Xcode

Comments are closed.