开发者

Xcode easily add multiple files to a target

开发者 https://www.devze.com 2023-04-12 14:02 出处:网络
开发者_Python百科I\'ve created a new target for unit tests in Xcode 4.2, and obviously i need to bring in certain application files into that target. But there is a lot, and it seems cumbersome toclic
开发者_Python百科

I've created a new target for unit tests in Xcode 4.2, and obviously i need to bring in certain application files into that target. But there is a lot, and it seems cumbersome to click each .m file then click TargetMembership and tick the new target box.

Is there an easier way to do this in Xcode that i'm missing?

Thanks


I though't i'd return to this with an improved answer. It's still difficult to do this via Xcode main interface, as if you filter for .m and try and do CMD-A to select all, it selects the folders too, so you can't add these to the target.

However, if you go to Project Settings > Build Phases > Compile Sources. You can click the + button, filter .m files, and you can CMD-A to select all here.

This works.

Xcode easily add multiple files to a target


If the files are all in a single directory, delete the directory from the project (remove reference only), then re-add it. Xcode will ask you which targets you want the files to be added to when you re-add it.


Select all the .m files in the "Project Editor" (cmd-1), show the "Utilities View" (opt-cmd-0) and click the new target in "Target Membership". Be careful not to select files that do not belong to a project such as .h files.


create a static or dynamic library, to which both executables link.


If you duplicate and existing target instead of creating a new one from scratch, all the existing files will be a member of the new(duplicated) target as well.


In 2016 you can now use both an AppTest and LogicTest target so you don't have to fiddle around with target settings.

You don't need to add any files to the AppTest target since it will have access to all main target files, and put pure logic tests in LogicTest.


In Xcode 10

You can also select multiple files in Project navigator and then, in the "Inspectors" right side pane you can modify Target Membership:

Xcode easily add multiple files to a target

0

精彩评论

暂无评论...
验证码 换一张
取 消