Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to copy a build phase to another target in Xcode?

Tags:

copy

xcode

build

I have a Copy Bundle Resources build phase which contains 200 resources. And now I have to make a new target as different kind. (app -> static lib) So unfortunately, I can't just duplicate the target :(

Anyway it's nonsense adding each resources one-by-one by hand. I tried to duplicate them at once but all I did failed. I made a new window and tried to drag them into the new target's phase, but it didn't worked.

How can I copy the Copy Bundle Resources build phase to another target? The target is in same project, so there is no file referencing problem.

like image 851
eonil Avatar asked Jan 02 '12 13:01

eonil


People also ask

How do I change project target in Xcode?

Changing the target name is just as simple. Click on the project name at the top left, then select a target name on the right pane followed by pressing "Enter".

How do I get building phases in Xcode?

To view the build phases for a target, select the target and navigate to the Build Phases tab, as shown in the following figure. To add a new build phase, click the Add button (+) and select an appropriate build phase from the pop-up menu. Xcode disables any menu options that aren't valid.

How do I select targets in Xcode?

To view and add dependencies, select a target and open its build phase settings. The Dependencies build phase contains the targets that Xcode must successfully build before it builds the current target. Xcode can build multiple dependent targets simultaneously if there are no interdependencies between those targets.


1 Answers

I solved this by opening my .pbxproj file in a text editor and doing some hunting for the right lines related to my target.

It's tricky, because Xcode uses a system of ids to populate the project file (ps. I did this while migrating from Cocoapods to Carthage, so I'm not using that setup)

It takes a little work finding the id of your target, but in Xcode 9, you should have something similar to

targets = ( EDBC6D6D1E0150850033868B /* target 1 */, EDF960C71E1963E0001A29CE /* fancy target */, EDF960D71E196DF3001A29CE /* Service Extension */, );

in the /* Begin PBXProject section */ section that describes the project. Search the .pbxproj file for your id to find the similarly structured buildPhases that lists ids for your targets build phases.

buildPhases = ( 47120FBF1F4343A900C27821 /* Sources */, 4712100B1F4343A900C27821 /* Frameworks */, 4712100D1F4343A900C27821 /* Resources */, 471210251F4343A900C27821 /* ShellScript */, 476673451F5F1ACD00567450 /* Embed App Extensions */, );

Now, find where the required id (in OPs case, Resources) and you'll find the list of resources. You can compare these to the list of your source target and copy and paste.

like image 125
wsgeorge Avatar answered Sep 28 '22 06:09

wsgeorge