Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode - Automatically add all files in a folder to a target

In Xcode, is there a way to specify that all files in a folder are compiled by a target. Eg. the 'Test' target automatically compiles all files in the 'Tests' folder, whereas the 'App' target compiles everything in the 'Sources' folder.

Today, the way I'm doing it, is to add a file to a target every time I create it. This feels a bit error prone and redundant since the files are already organized in the correct folders.

Thanks.

like image 417
Akshay Rawat Avatar asked May 19 '10 20:05

Akshay Rawat


People also ask

How do I add files to target in Xcode?

You can also add new apps, system extensions, test suites, and other types of targets to your project. To add a new target: Choose File > New > Target. Select the platform for the new target.

How do I add files to a folder in Xcode?

Xcode offers several ways to add existing files and folders to your project: Drag the files from the Finder into the Project navigator. Click the Add button (+) in the Project navigator's filter bar, and choose Add Files to “projectName”. Choose File > Add Files to “projectName”.

What is create folder references Xcode?

Xcode relies on filesystem organization by keeping a reference to a "physical" file or folder. That is why you may have all the classes, images, plists, and other parts of your projects stored in the same folder, while the references to these parts are being kept organized into respective groups within Xcode project.

What is a group in Xcode?

A folder in Xcode represents a folder in the file system. A group in Xcode is a "fake" folder which does NOT represent a folder in the file system. It is common to use a combination of groups and folders for a given Xcode project. Follow this answer to receive notifications.


1 Answers

This is completely broken in Xcode. Adding folders by folder reference (@Pavel's answer) should be correct - but it just doesn't work. See also https://stackoverflow.com/a/42600782/2518722. I'm using Xcode 8.3 (update: still broken in Xcode 11), but it's been broken for many generations prior, too.

There isn't a perfect workaround, but this is what I do:

  1. Drag the directory into the project
  2. When asked, set options as follows:
    • Select Create groups for any added folder (ie, the opposite to what you think would be right)
    • Deselect Copy files if needed (because you want a link, not a copy).

Now any changes to files in the shared directory will be reflected in Xcode, which is good.

But, there's no way of refreshing the group. (Someone please tell me if I'm missing something obvious here.) So if you've added new files to the directory, you have to remove the group in Xcode and re-add it before those files show up. This is obviously inconvenient, but at least it's not too prone to user error - and is better than adding files manually one-by-one.

Have to say I find it pretty unbelievable that such a simple and necessary feature of a development environment is so broken here.

like image 144
HughHughTeotl Avatar answered Sep 21 '22 15:09

HughHughTeotl