views:

790

answers:

3

Right now I'm using a few scripts to generate files that I'm including as resources in XCode. The thing is I'm running the script, then deleting from the project, then adding back into the project. There must be a way to automate this last step, so that the script can generate the files and automatically add them into the xcode project for me.

I'm using bash but any language examples would help.

Thanks, Andrew

+1  A: 
e.James
Thanks! In my case, I don't know the output files ahead of time. I'm looking to dynamically add files to the project, in some kind of sub-group. Is that possible? Or am I missing something about your example?
Andrew
Hmm. That's tricky. For what purpose are the files being added to the project? Do they just need to be copied into the Application bundle, or do they need to be compiled with the rest of the code? I can think of a few solutions, but I'll need to know a little bit more about how you need to use the files after they have been generated.
e.James
Thanks for the response! Basically, the files just need to be copied into the main bundle. They are only assets. But since the actual asset names are often changing or new ones are being added, I don't know all the names ahead of time, except their common extensions and their directory path. The way they are "generated" is they are checked into SVN :) I'm just looking for a way to save me time by having to click on "add existing file..." and then adding them manually... would much prefer an "svn update" followed by a compile :) Thanks!
Andrew
Andrew, did you find a solution for this?
coob
Not yet, the add script stuff was very useful and I've done that now, but I still can't find a way to automatically add files to a project. Any ideas?
Andrew
A: 

If you already have the files somewhere on your system, relative to your source root, you can always add a "Copy Files" phase. This will allow you to specify a directory where your resources should be copied from.

You can combine this with the Build Script phase answer provided to you already. For instance, run a script to check out your assets from Subversion into a subdirectory of your project, and then follow that up with a Copy Files phase that copies from "$(SRCROOT)/Assets".

Michael Nachbaur
Excellent idea. This coupled with the above example does exactly what I needed at the time, I'll definitely be doing this for the next update of my app.
Andrew
A: 

Basically, the files just need to be copied into the main bundle

In that case just add a folder reference to the project (Create a folder in your project folder and then drag it into your projects "Resources" group (in the "Files & Groups" list; then in the sheet that appears select the "Create Folder References for any added Folder" radio button) and Xcode will copy the folder and all of its contents into the target bundle at build time.

geowar
This would have totally worked too, and is much easier :) The only thing it changes is you can't use functions like [UIImage imageNamed:] because the files stay in the folder within the bundle. But a great solution none-the-less.
Andrew