I am using Xcode 7.0.1 Swift 2 iOS 9. While playing sound I get this error:
"fatal error: unexpectedly found nil while unwrapping an Optional value"
and this is my code:
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
playSound(enumerator![indexPath.item] )
}
func playSound(soundName: String)
{
let coinSound = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource(soundName, ofType: "m4a")!)
do{
let audioPlayer = try AVAudioPlayer(contentsOfURL:coinSound)
audioPlayer.prepareToPlay()
audioPlayer.play()
}catch {
print("Error getting the audio file")
}
}