0

I am trying to create a sound when A button is pressed in Swift. Since I do not know how to do that I am following answers regarding that subject on stack overflow. Unfortunately all answers involve passing nil into a paramter, which I cannot do in Swift 2.0. Here is example code of how they play sound when a button is pressed.

Swift, how to play sound when press a button

As you can see answers involve passing nil as an argument into a parameter when initializing the audio player object.

Is there anyway around this?

Community
  • 1
  • 1
Harshil.Chokshi
  • 671
  • 15
  • 26

1 Answers1

1

To initialize the player use:

let audioPlayer = try! AVAudioPlayer(contentsOfURL: yourSoundURL)
Rafał Sroka
  • 39,540
  • 23
  • 113
  • 143