I have an Xcode project with two targets. I want to share assets between the two targets so as to avoid duplicate files.
What I've tried:
- Create SharedAssets.xcassets
- Add SharedAssets.xcassets to both targets (when you create the .xcassets folder, you can select which targets to add it to)
- Add a
.wavfile to SharedAssets.xcassets - Reference the
.wavfile in code
Result:
The .wav file can't be found by either target.
Question:
Why are both targets unable to find the .wav file? How do I share assets between two targets?
Thank you!
Edit:
I'm using a SpriteKit SKAction to load the file from inside an SKScene:
private var sound: SKAction?
override func didMove(to view: SKView) {
sound = SKAction.playSoundFileNamed("mySound.wav", waitForCompletion: false)
}
I'm then playing the sound like this:
if let action = sound {
self.run(action)
}
This strategy works perfectly if I reference a .wav file in the main bundle, but fails when referencing the file in SharedAssets.xcassets.
Edit #2:
I am able to successfully use images stored in SharedAssets.xcassets -- so, it's a problem with sounds.
Instead of putting the
.wavfile in SharedAssets.xcassets, I kept it where it was in the bundle and simply added it to the second target under "Target Membership".Doing this for each
.wavfile solved the problem.