I have a main target that have certain files included under its target -> Build Phases -> Compile Sources. I'm starting a unit test and would like the unit test to include the same files as the main target. Is there a way to copy and paste the files included in one target to another target?
Asked
Active
Viewed 6,501 times
3 Answers
23
Yes, you can follow these steps:
- Select all Compile Sources on the main target.
- Right click on the selection and choose Reveal in Project Navigator (
CMD
+Shift
+j
). The files will be selected in the left pane. - Select another target.
- Drag and drop the selected files from Project Navigator to Compile Sources of another target.
Xcode 9.2 Update:
It looks like in Xcode 9.2 you can select only up to 150 items at once to use Drag and drop. If you want to copy more items you can do it in batches.

kowal
- 899
- 8
- 9
-
2Drag and drop didn't work for me in Xcode 7 but I could select the target in the "Target Membership" section on the Utilities pane (View > Utilities > Show Utilities). If the Target Membership section won't show up, try selecting a .m file first prior to revealing the selected files in Project Navigator. – jlukanta Jun 14 '16 at 16:36
-
@Sid It looks like in Xcode 9.2 you can select only up to **150 items** at once to use Drag and drop. If you want to copy more items you can do it in batches. I've updated the main answer. – kowal Jan 24 '18 at 10:23
-
Xcode 13.0: i tested selected all Compile Sources(377 files), then Reveal in Project Navigator, Drag and drop the selected files to another target's Compile Sources, and working fine. – JNYJ May 10 '22 at 03:16
11
You can edit the PBXSourcesBuildPhase section in your ".pbxproj" file. You cand find the file by looking into your ".xcodeproj" file ( right click the project file + show package contents ). After you find the file look for "PBXSourcesBuildPhase". After you find the collection you can just copy/paste source files from one target to the others.

filo
- 677
- 7
- 19
-
1Not quite easy to find the correct targets (I have about 20 targets in the project). So I just put a new source file into the target I'm looking for to identify it in the .pbxproj file. But with that, the solution works like a charm for me. – d4Rk Oct 24 '13 at 07:01
-
Indeed this seems to work. Was a bit worried when I observed that checking the files manually to the new target generates different file identifiers from what the same files had in another target, but reusing the same ones doesn't seem to do harm. – villapossu Jul 12 '18 at 11:30
0
You can create a duplicate of the target by right-clicking the target and selecting Duplicate. Or press Command+D.
You can then modify the new target's build settings as needed.

CodeSmile
- 64,284
- 20
- 132
- 217
-
10After duplicating an app target, how can I switch it to be a unit test bundle target? – Richard Jul 08 '13 at 18:15