This is the code I have written but I am to new to understand how to fix this error. Every time I run the app the build is successful, but then when I go to tap on the button/key, it gives me this error.
Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value
import UIKit
import AVFoundation
class ViewController: UIViewController {
var player: AVAudioPlayer!
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func keyAPressed(_ sender: UIButton) {
playSound()
}
func playSound() {
let url = Bundle.main.url(forResource: "C", withExtension: "wav")
player = try! AVAudioPlayer (contentsOf: url!)
player.play()
}
}