Skip to content

Instantly share code, notes, and snippets.

@JosephTLyons
Created July 18, 2019 11:51
Show Gist options
  • Save JosephTLyons/d7af87de3c1d51b5c9d50baf8d94ec6d to your computer and use it in GitHub Desktop.
Save JosephTLyons/d7af87de3c1d51b5c9d50baf8d94ec6d to your computer and use it in GitHub Desktop.
Angela Yu Lesson 87: Create a Method to Contain the Sound Playing Functionality (Solution)
@IBAction func notePressed(_ sender: UIButton) {
playSound("note" + String(sender.tag))
}
func playSound(_ fileName: String) {
let soundURL = Bundle.main.url(forResource: fileName, withExtension: "wav")
do {
try audioPlayer = AVAudioPlayer(contentsOf: soundURL!)
}
catch {
}
audioPlayer.play()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment