When duplicating a target in Xcode, is there any way to set the name that the target will have before or as it is created?

StackOverflow https://stackoverflow.com/questions/10335705

Duplicating a target in Xcode is a great way to create multiple app or framework/library products that have somewhat different features using the same codebase as a result of conditional code controlled by environmental variables set within the target build settings or related schemes. First duplicate your known-working basic version, then set the environmental variables each target will use, then start splitting up your code behavior with inline preprocessor #ifdef statements.

However, any duplicated target will be named "Original Target Name copy". This can be renamed, but the info.plist will also have this name, it may also appear in a couple of essential build settings, and it can be a tedious and error-introducing process to remove all references to the non-informative "copy" version of the duplicated target name depending on how you do it. When I create iOS frameworks this seems to be especially prone to introducing issues.

My question is whether there is any technique for duplicating a target which allows you to specify the new target name at the time of duplication, so there is never a temporary wrong target name or any files being created which contain that temporary wrong name. Or, alternately, if there is some way to use the "refactor" functionality to fix this is an automated way.

If there is some kind of wrong assumption contained within the question that explains why this feature hasn't been included in Xcode, let me know. I'm using 4.3.

有帮助吗?

解决方案

Unfortunately, I'm pretty darn sure there's not any current UI for this, although I strongly agree that it would be a huge improvement; I can't speak for everyone, but I pretty much never want a target named Foo copy. I would suggest filing a Radar.

其他提示

You could, with some effort, use CMake for that. It's a build system generator.

It may be difficult at first to learn and setup the project, and some things are (currently) not easily possible for Xcode (like resource adding) but it would make creating new targets with a basic configuration very easy.

Basically, you write CMakeLists.txt files in your source tree to define your libraries and targets, then define the source files, etc., then generate the Xcode project each time.

Adding a new target would be very easy:

  1. ADD_EXECUTABLE( Target_Name Source_Files )
  2. SET_TARGET_PROPERTIES( Target_Name PROPERTIES COMPILE_DEFINITIONS Your_Additional_Defines )
  3. Rerun CMake. (Its not even required to close the Xcode project)

Disadvantages:

  • Takes time to setup.
  • Sometimes research is necessary to get some things to work
  • Some things are currently not well supported via CMake

In Xcode 6 (not sure about earlier versions) duplicating a target will still generate the " copy" appendage and rename all localized menus for example. But, it is reversible by updating the Product Name under Packaging in Build Settings / All. Info.plist will still have to be taken care of as well as Scheme naming though.

Doubleclick on the target to at least rename thetarget ... still looking to rename the product, but that's not so important if you can rename everything else (like the displayname etc))

  • select project in Navigator panel
  • select Target you want to duplicate
  • right mouse click and choose "Duplicate"
  • Rename Target in XCode: click on selected Target and inline edit starts.
  • Open Terminal and go to your project directory/folder
  • Run svn status to see the changes XCode just has made.
  • XCode has created new Infocopy.plist file and has added under version control if you use one. Typically you want to choose different name so follow these steps:
  • Cancel version control addition: $> svn revert Infocopy.plist
  • Rename it: $> mv Infocopy.plist YourNameInfo.plist
  • Add it to version control: $> svn add YourNameInfo.plist
  • Set the new name in your new Target Build Settings named "Info.plist File"
  • Rename target file properly: $> mv OrigTargetCopy.xcscheme YourTargetName.xcscheme
  • Add the new target file under version control: $> svn add YourTargetName.xcscheme
  • Rename you Product in your new Target Build Settings named "Product Name"
  • Very likely you will also want to set new "Preprocessor macros" Build Settings for your new Target.
  • Set proper values your YourNameInfo.plist
  • Set Target assignment for target specific files. Typically YourNameInfo.plist shall be part only of you new target. There may be plenty of other similar files (icon, splash screen, other graphics, etc).
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top