Im extremely new to iOS development, and I'm trying to make a simple soundboard app.
i've watched various tutorials, and videos, but i can't seem to get my code to work like it does in the example. - maybe because the video is objective C or an older version of swift - I dont know.
https://www.youtube.com/watch?v=hzQCLdd2X-A - seems to be the easiest way i've found.
copying his code:
import UIKit
import AVFoundation
class ViewController: UIViewController {
var sound01 = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("filename", ofType: "mp3")!)
var audioPlayer = AVAudioPlayer()
override func viewDidLoad() {
super.viewDidLoad()
audioPlayer = AVAudioPlayer(contentsOfURL: sound01, error: nil)
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
in his version, he doesn't get any errors: - yet in mine, i get:
Incorrect argument label in call (have 'contentsOfURL:error:', expected 'contentsOfURL:fileTypeHint:')
when you use the fix it suggestion, it becomes:
audioPlayer = AVAudioPlayer(contentsOfURL: sound01, fileTypeHint: nil)
now i get this error:
Call can throw, but it is not marked with 'try' and the error is not handled
what am I doing wrong?