I've been trying to build an IOS app that will allow me to click a button and have audio play and I'm getting stuck on this error only instance methods can be declared @IBAction. I've had a search and it doesn't seem like I've closed it out of the class or anything like that but it still doesn't want to work
import UIKit
import AVFoundation
class LevelAStartingSoundViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
@IBAction func Sbutton(_ sender: Any, forEvent event: UIEvent) {
playSound(sound: "Ssound", type: "wav")
}
}
}
If you reformat your code (Ctrl + i), you'll notice that
Sbuttonis insideviewDidLoad.You need to move it outside.