I made a Game on Xcode 7 beta using SpriteKit and Swift, I tried to put Audio in it but it's not posible because Xcode found 3 errors, I'm beginner and I don't know how to fix them.
import AVFoundation
var audioPlayer = AVAudioPlayer()
func playAudio() {
// Set the sound file name & extension
var alertSound = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("Flip 02", ofType: "wav")!)
// Preperation
AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, error: nil)
AVAudioSession.sharedInstance().setActive(true, error: nil)
// Play the sound
var error: NSError?
audioPlayer = AVAudioPlayer(contentsOfURL: alertSound, error: &error)
audioPlayer.prepareToPlay()
audioPlayer.play()
}
The error of code are here:
Code 1:
AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, error: nil)
Error 1:
Extra argument 'error' in call
Code 2:
AVAudioSession.sharedInstance().setActive(true, error: nil)
Error 2:
Extra argument 'error' in call
Code 3:
audioPlayer = AVAudioPlayer(contentsOfURL: alertSound, error: &error)
Error 3:
Cannot find an initializer for type 'AVAudioPlayer' that accepts an argument list of type '(contentsOfURL: NSURL, error: inout NSError?)'
Your contribution may will help me. Thanks.