この問題を解決するために使用できる 3 つの方法があります。
- try を使用してオプションの AVAudioRecorder を作成しますか?
- AVRecorder が返されることがわかっている場合は、暗黙的に try! を使用できます。
- または、try / catch を使用してエラーを処理します
試してみますか?
// notice that it returns AVAudioRecorder?
if let recorder = try? AVAudioRecorder(URL: soundFileURL, settings: recordSettings) {
// your code here to use the recorder
}
使ってみる!
// this is implicitly unwrapped and can crash if there is problem with soundFileURL or recordSettings
let recorder = try! AVAudioRecorder(URL: soundFileURL, settings: recordSettings)
試す/捕まえる
// The best way to do is to handle the error gracefully using try / catch
do {
let recorder = try AVAudioRecorder(URL: soundFileURL, settings: recordSettings)
} catch {
print("Error occurred \(error)")
}