Disabling some files in Xcode project from compilation
Asked Answered
A

4

14

I have started a new project in Xcode by duplicating an existing folder, because my new app will have a lot of common features with the old one.

The problem is that the new app won't be using a framework I used in the old app. When I deleted the framework, of course all files including that framework raised errors.

Basically I want to disable all syntax checks, dependency checks, etc. on many files. I want Xcode to ignore these files, although they are in the project tree. Later when I revise them I will manually enable them again. This way I can compile and test my small changes for errors without fixing all errors it causes in the "not revised" files, which I will be fixing in the future anyway.

I could delete them from the project tree and then add them again one by one when my job's done, but I don't want to do this because my project tree might get messed up and there should really be another way to accomplish this.

I tried removing those files from all target memberships, but it didn't help.

Antoninaantonino answered 26/9, 2012 at 11:32 Comment(0)
M
22

If you need to remove a lot of files, you could create User-Defined Build Setting which should be called EXCLUDED_SOURCE_FILE_NAMES. And add file names or patterns.

In my case I selected the target I wanted to omit some files, Editor -> Add Build Setting -> Add User-Defined Setting (at first this is greyed out somehow. I selected the project file (just above TARGETS) then reselected target file and was able to create User-Defined Setting) -> name it EXCLUDED_SOURCE_FILE_NAMES -> value something like PREFIX*

Of course you can create User-Defined Setting for whole project that way all targets will have it.

Example how it may look: enter image description here

Original answer: http://lists.apple.com/archives/xcode-users/2009/Jun/msg00153.html

Myranda answered 3/6, 2014 at 8:34 Comment(1)
In case of option is still grayed out. https://mcmap.net/q/827250/-xcode-5-0-apple-where-is-add-build-rule-gone – Cowherd
A
21

In Xcode 9, I am not sure about older versions, go to:

Build Settings -> Build Options -> Excluded Source File Names

Add all file names you want excluded. You can even do wildcard matching.

Bellow is an example of how I have excluded all files starting with dev- and ending with .cc for all schemes except for a Debug scheme that is built for Simulator. All Debug Simulator builds exclude files starting with release- and ending with .cc

enter image description here

Hope this helps!!

UPDATE

I had a similar problem with frameworks and you can exclude frameworks from being embedded into your app with this too!

My problem was that I had 2 frameworks, one was built for the simulator and the other was build for ARM. iTunes Connect complained about me including the simulator one with the app.

If you have many frameworks this help with reducing the app's size too.

Ahlers answered 27/10, 2017 at 20:15 Comment(3)
Holy hell, this is amazing. I've spent a day fighting a duplicate framework in an archive πŸ˜„ – Biramous
Your answer helped me solve this problem, but then another problem arised. My code isn't able to find that file that was excluded. I need to exclude the file from compiling, but I still need to be able to access the file using the Bundle.path(...). – Lengthen
This works for frameworks too! Can exclude an entire framework by just adding its name. – Rocambole
L
0

Check out the answer here

Xcode: Is there a location/flag to prevent a Class from compiling?

In a nutshell remove the file(s) from the project target.

Lebbie answered 26/9, 2012 at 11:46 Comment(0)
C
0

As dirty hack you can try exclude not files, but its code by using #ifdef NotCompile + #endif as it's done in C\C++ with .h with adding\removing #define NotCompile in YOURPROJECT-prefix.pch

Competency answered 26/9, 2012 at 11:46 Comment(0)

© 2022 - 2024 β€” McMap. All rights reserved.