我有這樣的功能:`NSDictionary`不能隱式轉換爲`[NSObject的:AnyObject]`
func audioRecordingSettings() -> NSDictionary {
return [
AVFormatIDKey : kAudioFormatMPEG4AAC as NSNumber,
AVSampleRateKey : 16000.0 as NSNumber,
AVNumberOfChannelsKey : 1 as NSNumber,
AVEncoderAudioQualityKey : AVAudioQuality.Medium.rawValue as NSNumber
]
}
然後我定義的另一個:
func startRecordingAudio() {
var error: NSError?
let audioRecordingURL = self.audioRecordingPath()
audioRecorder = AVAudioRecorder(URL: audioRecordingURL, settings: audioRecordingSettings(), error: &error)
//Here the error comes.
}
它要求我以後添加爲[NSObject: AnyObject]
audioRecordingSetthings()
,我不認爲這是正確的解決方案。 因爲當我在另一個class
中調用startRecordingAudio()
時,它與Unexpectedly found nil
崩潰。
'kAudioFormatMPEG4AAC作爲NSNumber'應該是'的NSNumber(無符號整型:kAudioFormatMPEG4AAC)' ,因爲基本上不能直接將對象作爲對象進行鑄造。 – holex