Thread 1: "-[Xylophone.ViewController buttonClicked:]: unrecognized selector sent to instance 0x7ff83a6074e0"

579 Views Asked by At

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?

1

There are 1 best solutions below

0
On

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: enter image description here

When I had more than one connection it gave me this error.