简体   繁体   English

`NSDictionary`不能隐式转换为`[NSObject:AnyObject]`

[英]`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.

相关问题 &#39;[NSObject]&#39; 不能转换为 &#39;[AnyObject]&#39; - '[NSObject]' is not convertible to '[AnyObject]' (NSObject,AnyObject)不能转换为DictionaryIndex <NSObject, AnyObject> - (NSObject, AnyObject) is not convertible to DictionaryIndex<NSObject, AnyObject> &#39;NSMutableSet&#39;不能隐式转换为&#39;Set <NSObject> &#39; - 'NSMutableSet' is not implicitly convertible to 'Set<NSObject>' Alamofire参数 - NSDictionary不能转换为[String:AnyObject] - Alamofire Parameters - NSDictionary is not convertible to [String : AnyObject] ObjC到NSDictionary到NSObject的Swift转换:AnyObject - ObjC to Swift conversion of NSDictionary to NSObject : AnyObject “ [NSObject:AnyObject]”与“ NSDictionary”不同,RKPathMatcher出现问题 - '[NSObject : AnyObject]' is not identical to 'NSDictionary', trouble with RKPathMatcher Swift中的错误:(键:AnyObject,值:AnyObject)&#39;无法转换为&#39;NSDictionary&#39; - Error in Swift : (key: AnyObject, value: AnyObject)' is not convertible to 'NSDictionary' “ AnyObject”与“ [NSObject:AnyObject]”不同 - 'AnyObject' is not identical to '[NSObject : AnyObject]' Swift 2.0 - Google Analytics事件构建器错误 - NSMutableDictionary无法转换为[NSObject:AnyObject] - Swift 2.0 - Google Analytics Event builder error - NSMutableDictionary is not convertible to [NSObject : AnyObject] [NSDictionary] !? 不能转换为[NSDictionary]? - [NSDictionary]!? is not convertible to [NSDictionary]?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM