Exception NSException * "-[Xylophone.ViewController buttonClicked:]: unrecognized selector sent to instance 0x7faa47409400" 0x0000600002148690
I'm trying to make a xylophone app in which the buttons would play different sounds, there are 7 buttons however only the first button doesn't work, all other buttons work. on pressing the first button the app crashes.
Here is the code:
import UIKit
import AVFoundation
class ViewController: UIViewController {
var player: AVAudioPlayer!
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func keyPressed(_ sender: UIButton) {
playSound(soundName: sender.currentTitle!)
}
func playSound(soundName:String) {
let url = Bundle.main.url(forResource: soundName, withExtension: "wav")
player = try! AVAudioPlayer(contentsOf: url!)
player.play()
}
}
what is the issue here?
I faced the same issue and here's how I solved it: right-click every button you have in
Main.storyboard
, and check the connection it has in the small menu like this:When I had more than one connection it gave me this error.