Swift - Error Domain=NSOSStatusErrorDomain Code=-42 "(null)"

Hello,


I've been trying to figure out why I keep geeting this error. I looked up code -42 and it means too many files open. The app works fine if I stay in the same view, but when I switch between views several times I get the error. Here is part of my code:



let A1path = NSBundle.mainBundle().pathForResource("A1", ofType: "wav")

let A1Url = NSURL(fileURLWithPath: A1path!)

do {

try A1Sound = AVAudioPlayer(contentsOfURL: A1Url)

A1Sound.prepareToPlay()

} catch let err as NSError {

print(err.debugDescription)

}



func playA1() {

A1Sound.currentTime = 0

A1Sound.play()

}


func stop() {

if (A1Sound.playing){

A1Sound.stop()

A1Sound.currentTime = 0

}

}


Can someone please help? Is there a way to close the files before I switch views or some other way to fix the error. I put the stop function int he menu IBAction function and it works fine.

Replies

I'm getting this error as well. Did you find a workaround by any chance? Thanks.