Reputation: 52231
I'm seeking advice on how to share assets between 4 targets in my project: A.app, B.app, C.app, D.app
In the 'Run Script' phase, copy files from Assets.bundle into the *.app targets, like this:
cd "${BUILT_PRODUCTS_DIR}" ls Assets.bundle | sed '/Info.plist/d' | xargs -t -I {} cp -r Assets.bundle/{} "${CONTENTS_FOLDER_PATH}/"
However when I run the app, the UI looks wrong. The .xib's gets loaded, but no images gets loaded! The image files and nib files seems to have been copied correct into the .app folder. My hypothesis is that a compiled .nib file assumes that it's located inside the Assets.bundle folder, thus explaining why it doesn't work when it's located outside the Assets.bundle folder.
Am I missing something in this approach?
Make a Assets.xcconfig file that is #imported by the {A,B,C,D}.app targets.
Mirror the 'Copy Bundle Resources' from the A.app target to the {B,C,D}.app targets
With a ruby script I can update the 'project.pbxproj' file.
Maintain 'Copy Bundle Resources' manually on {A,B,C,D}.app targets.
EDIT: I want to abandon this 'Target Membership' approach, because it's a big project and multiple people are contributing.
In this project I have >1000 image files and >150 .xib files. There is much legacy code that uses hardcoded path lookups. Rework will take time. I have done this change on small project. This is a very elegant solution. However a rework of this size will take lots of time.
Upvotes: 1
Views: 3583
Reputation: 4859
I know is an old question, but I had the same problem so I discover a way to do this with the xcodeproj
library. If you want you can check this at: https://github.com/dalu93/DLSharedBundleResources/
It takes two targets as params (one as "complete" target, the other one as "to-complete target") and it adds missing files. If you open the .rb
file you find also a blacklist
var where you can insert an array of file names that you want to exclude from the "merge".
I hope it helps you
Upvotes: 3
Reputation: 51
Why not just use XCode's integrated handling? Select an asset, select which targets it should be included with in the 'Target Membership' section in the utilities panel on the right. I use this to switch xibs, graphics etc. between free and paid versions, works great for this at least.
Forgot to mention: If you're including variants of files with the same name, to make it easier put them in a folder or bundle so you can separate them. Then add a define to the target with the bundle/folder name so you can automatically load them from any path.
Upvotes: 5