35

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

asked Oct 11, 2011 at 21:18

7 Answers 7

66

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

saurabh
6,7957 gold badges45 silver badges64 bronze badges
answered Jun 28, 2013 at 10:23
Sign up to request clarification or add additional context in comments.

3 Comments

What a mess! Thanks for sharing - pretty sure it was bloody easy with Xcode 3 to filter by file type in the navigator thingie..
@bandejapaisa Holy guacamole. This is the jackpot answer 🏆
@bandejapaisa And if you have multiple libs, folding tree nodes will unselect them 👌
7

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.

answered Nov 16, 2011 at 22:58

Comments

2

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.

answered Oct 11, 2011 at 21:27

1 Comment

I said easy, and there is a lot of files in a lot of directories..... selecting all the .m files in the project explorer is tiring.
2

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.

answered Jul 21, 2014 at 22:26

Comments

1

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

answered Oct 11, 2011 at 22:02

1 Comment

Um, not too bad an idea I suppose.
1

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

answered Feb 26, 2019 at 13:13

2 Comments

Where can I find the Target membership in the Xcode 13.2.1
@sejn , it is part of the xcode's inspectors panel. If it is not open by default, then look the top right corner of xcode. Note, it appears only when you have one or more files selected in the project navigator.
0

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.

answered Oct 29, 2016 at 8:19

2 Comments

Can you provide any documentation and / or tutorial? I quite did not get your answer but I'm curious to know more about it.
Read online about application vs. logic tests (logic tests are smaller and faster), but when you add a new test target in Xcode, it defaults to using your main target as your host app. What this means is your tests have access to everything in your main target bundle (code, resources), thus you can import any of your classes (even view controllers) - without having to explicitly include them in your test target. Thus, no need to manually click each .m file and include them in your app test target.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.