6

Is there a quick way to synchronize two (or more) targets in Xcode? This becomes an issue when I forget to add a new file to my unit test & integration target. Then I have to go hunting to see what I forgot to add. I can duplicate my "development" target and then re-add the "unit testing" configuration, but that's a pain. Is there an easier way?

EDIT:

I like John's answer below but ultimately I used the answer from here, that involves manually editing the project file. With multiple missing files that was the quickest way.

Community
  • 1
  • 1
EightyEight
  • 3,430
  • 4
  • 36
  • 67
  • I would like to add that you can use this Fastlane plugin to scan your targets for unsynced files. This does not solve your problem but can help you or others find out the missing puzzle https://rubygems.org/gems/fastlane-plugin-itargetchecker – Cata May 12 '18 at 18:06

2 Answers2

5

your question focuses on the case where you are adding a single file to a target, and forget to check both boxes to add it to the target you want.

perhaps you mean that it is a pain to use the identity inspector, but i think this is a handy way to add in one file that i didn't properly get added to a second target. you can get to the identity inspector by first clicking on the file for which you want to inspect information, and then using Cmd-Opt-1, and then clicking the rightmost tab. notice near the bottom that for me, both targets are checked. for you, in the case of a file that didn't get added to both targets, one will be unchecked.

identity inspector

in the case of not remembering which files you added recently to a target:

  • if you have your project under source control, you can perform "View" -> "Version Editor" -> "Show Version Editor" (or Cmd-Opt-Shift-Return), and you'll get a text-based diff comparison of the XML representing your project versus what it looked like at the last commit. whatever is new is likely the set of files to look at for the checkboxes as in the picture above.
  • if not under source control, you may have to go through the files one by one, though you might be able to use the finder to sort your source by Date Modified, and jog your memory as to the file you added, then go straight to that. in terms of going through one by one, once the identity inspector is open, you should be able to just click on the first file in the list, then use the down-arrow to step through all files, and see which are in the desired set of targets and which are not.
john.k.doe
  • 7,533
  • 2
  • 37
  • 64
  • Thanks John, what if I have multiple files that need to be added to multiple targets? – EightyEight Jul 18 '12 at 21:54
  • 1
    in the first dialog that comes up when adding files (whether you are going through "Add Files" or drag them into the project), there will be a list of the targets that your project has. you just need to make certain that you check the targets you want. for example, for regular source, you probably want to check all, and for new unit testing source, you probably only want to check the target for unit testing. this will work for dragging in multiple files or selecting multiple files in the dialog. – john.k.doe Jul 18 '12 at 23:04
  • Please see ruby tool github.com/smirn0v/xcode-same-targets in case you want to check targets equality automatically. – Alexander Smirnov Jan 18 '14 at 21:04
-1

Copy the secondary target folder with all its files into primary target folder. Then just drag and drop secondary target xcodeproj into primary one in xcode.

innodeasapps
  • 473
  • 2
  • 8