Touch or Untouch a File in Xcode

In a previous post, Tell Xcode Not to Compile a File, I mentioned that when a new file is imported into Xcode, if the file type is a recognized, it will be added to the Compile Sources folder. From there, Xcode will manage if/when the file needs to be recompiled based on its current time stamp.

For example, if you edit and save a file, the time stamp will be updated and Xcode will recompile the file on the next build cycle.

If you ever need to force a recompile of a file, you can do a Clean of the project (see the Build menu in Xcode). Clean will delete all intermediate files such as precompiled headers, so on the next build Xcode will recreate the current target’s precompiled header files and all other files as needed. Depending on the size of your project, this may be a time consuming process.

Should you have a need to recompile a select file or two, a better option is to touch only those specific files. For those unfamiliar with touch, this refers to a unix utility of the same name that changes file access and modification times. From within Xcode you can touch a file by right clicking on a file in the Groups and Files window and choosing Touch from the drop-down menu:

Notice there is also an Untouch option in the menu, which will mark the file state as up-to-date, thus averting a compile of that file, on the next build.

  1. Ah, I’ve wondered what touch and untouch do. This explained it. I have a question though. If I want to force compile, I can also choose “compile” in that menu, right? The time that it’s compiled would be different but the result should be the same. The new version is compiled.

    I have used the “compile” command for graphics. Sometimes I would replace a graphic with a new version, but Xcode still used the old version. I would then right click and select “compile” to make sure it uses the new one. I wonder if touch would give me the same end result. Time to experiment.

Comments are closed.