bandejapaisa
bandejapaisa

Reputation: 26952

Xcode easily add multiple files to a target

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

Upvotes: 34

Views: 34160

Answers (7)

Dima G
Dima G

Reputation: 2025

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:

Target Membership

Upvotes: 1

bandejapaisa
bandejapaisa

Reputation: 26952

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.

screenshot

Upvotes: 65

Kreeble Song
Kreeble Song

Reputation: 131

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.

Upvotes: 0

Erdem Gezer
Erdem Gezer

Reputation: 3272

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.

Upvotes: 2

user1050660
user1050660

Reputation: 461

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.

Upvotes: 7

justin
justin

Reputation: 104698

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

Upvotes: 1

zaph
zaph

Reputation: 112857

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.

Upvotes: 2

Related Questions