The following code works fine with Xcode 7.2.1. After I upgraded to 7.3 I get a crash with: "unexpectedly found nil while unwrapping an Optional value"
var backgroundMusic: SKAudioNode!
func playBackgroundMusic(name: String) {
var delay = 0.0
if backgroundMusic != nil {
backgroundMusic.removeFromParent()
} else {
delay = 0.1 }
runAction(SKAction.waitForDuration(delay)) {
self.backgroundMusic = SKAudioNode(fileNamed: name)
self.backgroundMusic.autoplayLooped = true
self.addChild(self.backgroundMusic)
} }
didMoveToView(view: SKView) {
...
playBackgroundMusic("Music.mp3")
}
- I also tried cleaning the project, deleting all the Xcode Developer derived data, and verifying that the "Music.mp3" is being built into the main bundle.
- Going back to Xcode 7.2.1 and building works fine with the same code.
Been scratching my head on this one most of the day. Is there a better way to do this?