views:

38

answers:

2

I have an Xcode project. The project currently has four targets, and I am about to add more. Within the project are about 150 png files. I have all of these in a tree of groups in the Xcode "groups and files" panel.

I want to include these png files in some of my targets, but not in others. The thing is, I will always want either all of them or none of them. I don't want to pick and choose.

Is there a way to manage this? Basically, I want some targets to use all of the files in the "png files" group, and others to use none of them. If there is a way to include an entire tree of groups in a target, and remove the same tree from another target, without having to do each file individually, that would be ideal.

Thanks.

EDIT: starting a bounty on this due to the lack of response. If it's not possible to do the above, I would be interested in other ways to accomplish more or less the same thing -- for example would it help to make all the png files a shared library? Or to make them a target in and of themselves, and have some of my other targets depend on that one? In either case, I would need to know how to set the thing up.

My bottom line is that I want to do the whole thing as simply as possible. For example, it should be easy to add a file to the 150 and tell my project that it should be included in all targets that use that group of files.

A: 

Write a script and include it in the appropriate targets as Run Script Phases. Since it gets environment variables from Xcode it’s pretty easy for the script to copy files over to the right place. You can also pass more information to the script and maintain a clean, code-only Xcode project.

You’ll have a directory full of images, and every time the script runs (as you build the targets) it copies everything. To add an image, you add it to the directory without modifying the Xcode project.

Evadne Wu
+1  A: 

I am using the Xcode 3.2.3 right now. I am able to right click on a group, select get info then jump over to the 'Targets' tab and select my targets I want those files to go into. It works for me, is this what you are looking for?

Brent Nycum
Bingo . . . thanks! It says I have to wait 24 hours before awarding, but I think you have it.
William Jockusch
Actually there is one more piece of the puzzle that would be helpful, if the feature exists . . .Suppose I set group A to go into targets X, Y, and Z. Is there a way to tell it that if I later add more files to group A, those files should also automatically go into targets X, Y, and Z?Right now, it seems to stick with the default of whatever targets I used for the last file I added.
William Jockusch
Yea it seems that it sticks with the default for me as well. Maybe file a feature request with Apple. Another solution might be to create a bundle, you should only have to add the bundle to your project once and can manage the files inside of it from outside of Xcode. Bad problem to this is having to change your code up to use the new bundle and not the default main bundle.
Brent Nycum