Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
203 views
in Technique[技术] by (71.8m points)

build - 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.

question from:https://stackoverflow.com/questions/2869049/xcode-automatically-add-all-files-in-a-folder-to-a-target

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...