I have this function:
func audioRecordingSettings() -> NSDictionary {
return [
AVFormatIDKey : kAudioFormatMPEG4AAC as NSNumber,
AVSampleRateKey : 16000.0 as NSNumber,
AVNumberOfChannelsKey : 1 as NSNumber,
AVEncoderAudioQualityKey : AVAudioQuality.Medium.rawValue as NSNumber
]
}
Then I defined another:
func startRecordingAudio() {
var error: NSError?
let audioRecordingURL = self.audioRecordingPath()
audioRecorder = AVAudioRecorder(URL: audioRecordingURL, settings: audioRecordingSettings(), error: &error)
//Here the error comes.
}
It asks me to add as [NSObject: AnyObject] after the audioRecordingSetthings(), I don't think that's the correct solution.
Because when I called startRecordingAudio() in another class, it crashes with Unexpectedly found nil.
You just need to add
audioRecordingSettings() as [NSObject : AnyObject]in theAVAudioRecorderDelegate:Additionally I would change your method to: