18

I saw this and answers in stackO, but didn't find how to exclude folders.

I have 3 folders with a lot of .h , .m and .mm and i need to exclude them temporary, but not to remove references. How can i do that?

Nike Kov
  • 12,630
  • 8
  • 75
  • 122

4 Answers4

12

From looking at the post you link to. Here is how you do it:

  1. Go to Build Settings.

  2. Press the plus button and select "Add User-Defined settings"

enter image description here

  1. Give the new field the name of EXCLUDED_SOURCE_FILE_NAMES.

enter image description here

  1. Add the path to the folder: <Path>/FolderToIgnore/*. The asterisk denotes all the file in the folder.

enter image description here

That should do it.

Note: Make sure you add this to the right target.

Caleb Kleveter
  • 11,170
  • 8
  • 62
  • 92
  • 2
    Yep, this works! In Xcode 9 there is already such `User-Defined setting`: **Build Settings> Build Options> Excluded Source File Names** – Nike Kov Feb 24 '18 at 12:55
  • How to exclude folder only for release build? – phnmnn Mar 12 '19 at 15:50
  • 2
    @phnmnn, tap the arrow next to "Excluded Source File Names" and it will drop down to show `Debug` and `Release`. You can provide different options for each. – Jereme Jul 16 '19 at 17:22
7

xcode 9.2

Build Settings> Build Options> Excluded Source File Names

enter image description here

1mike12
  • 2,946
  • 3
  • 27
  • 36
6

Can't comment, but wanted to note that, unless I'm doing something wrong, when using the EXCLUDED_SOURCE_FILE_NAMES build setting as explained in the other answered, excluding a folder using something like */Folder/* won't exclude anything within sub-folders of Folder, but only files within it directly. If you had another folder, eg. /Folder/Subfolder/, you'd have to include */Folder/Subfolder/* as well in order to exclude any files within it. At least this is the case in Xcode 10.3.

Example:

[Folder]
    item.txt
    [Subfolder]
        image.png
    info.plist

*/Folder/* would exclude item.txt and info.plist, but not image.png.

*/Folder/Subfolder/* would exclude image.png.

Ohifriend
  • 352
  • 4
  • 10
  • 1
    Check out [this answer here](https://stackoverflow.com/a/55492478/8221836) that suggests dropping the asterisk to solve this problem. – zwilf Nov 21 '19 at 21:01
  • Another solution is to use groups without folders for every subfolder in excluded directory – Feridun Erbaş May 02 '21 at 10:38
  • To exclude everything in a folder at the root level of the project called "Folder" (including its subfolders), simply specify `Folder` (no `/*`) – Robin Stewart May 11 '21 at 23:33
4

This answer covers only how to exclude the files from the build or the matching file patterns.Exclude from the path or the folder has currently not been implemented in the Xcode

  • Select the editor
  • Select Add Build Setting
  • In Add Build Setting select Add User Defined Settings for this select the project for which you want to add the user defined settings.
  • Select the name of it as EXCLUDED_SOURCE_FILE_NAMES
  • Set the value as filename patterns,the files you want to exclude.

or

You can use the File Inspector and in the target membership simply uncheck the file which you do not want to include in your build

Similarly the same thing can be done compile sources category where you can select the file which you want to add to your build.

Pritish Vaidya
  • 21,561
  • 3
  • 58
  • 76