[英]`NSDictionary` is not implicitly convertible to `[NSObject : AnyObject]`
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. 它要求我在
audioRecordingSetthings()
之后添加[NSObject: AnyObject]
,我不认为这是正确的解决方案。 Because when I called startRecordingAudio()
in another class
, it crashes with Unexpectedly found nil
. 因为当我在另一个
class
调用startRecordingAudio()
时,它会在Unexpectedly found nil
时崩溃。
You just need to add audioRecordingSettings() as [NSObject : AnyObject]
in the AVAudioRecorderDelegate
: 你只需要添加
audioRecordingSettings() as [NSObject : AnyObject]
在AVAudioRecorderDelegate
:
AVAudioRecorder(URL: audioRecordingURL, settings: audioRecordingSettings() as [NSObject : AnyObject], error: &error)
Additionally I would change your method to: 另外,我会将您的方法更改为:
func audioRecordingSettings() -> [NSObject : AnyObject] {
return [
AVFormatIDKey : kAudioFormatMPEG4AAC,
AVSampleRateKey : 16000.0,
AVNumberOfChannelsKey : 1,
AVEncoderAudioQualityKey : AVAudioQuality.Medium.rawValue
]
}
You need to check the "AVAudioRecorder"
initializer which specifies: 您需要检查
"AVAudioRecorder"
初始化程序,它指定:
init!(URL url: NSURL!, settings: [NSObject : AnyObject]!, error outError: NSErrorPointer)
So, you need to convert setting to [NSObject : AnyObject]
. 因此,您需要将设置转换为
[NSObject : AnyObject]
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.