Morning
Im working through one of the Udemy AppBrewer courses and I've been looking at how I would solve one of the pieces of work. Ive done what I felt was logical but its returning an error.
Using Swift Im trying to play one of two sounds based on a button being pressed using the the tag value to define the sound to be played. The code works when I don't have any loop created.
Im trying to use an IF statement to review the tag value and then make a decision.
My problem is that I get a 'Use of unresolved identifier' which on review sounds like it doesnt understand one of my variables ( the one in the loop). I cant understand why this would be the case and I dont have enough knowledge on swift to disect it
Works out of the loop just not when Ive put in an IF statement
@IBAction func notePressed(_ sender: UIButton)
{
if sender.tag == 1 {
let soundURL = Bundle.main.url(forResource: "note1", withExtension: "wav")
}
else {
let soundURL = Bundle.main.url(forResource: "note2", withExtension: "wav")
}
do {
audioPlayer = try AVAudioPlayer(contentsOf: soundURL!)
}
catch {
print(error)
}
audioPlayer.play()
}
}
Error Use of Unresolved identifier "soundURL" "catch" block is unreachable because no errors are thrown into the Do Block
(not sure why my code format is so off)
Aucun commentaire:
Enregistrer un commentaire