Swift 2.0: Type of Expression is ambiguous without more context?

*爱你&永不变心* 提交于 2019-11-30 07:49:55
Stephan

To comply to the required [String : AnyObject] format required by recordSettings parameter; In addition to @Unheilig's answer, you'll need to convert your ints and floats to NSNumber:

let recordSettings : [String : AnyObject] =
[
    AVFormatIDKey: NSNumber(unsignedInt: kAudioFormatMPEG4AAC),
    AVEncoderAudioQualityKey : AVAudioQuality.Max.rawValue as NSNumber,
    AVEncoderBitRateKey : 320000 as NSNumber,
    AVNumberOfChannelsKey: 2 as NSNumber,
    AVSampleRateKey : 44100.0 as NSNumber
]

You could give the compiler more information:

let recordSettings : [String : Any] =
[
    AVFormatIDKey: kAudioFormatMPEG4AAC,
    AVEncoderAudioQualityKey : AVAudioQuality.Max.rawValue,
    AVEncoderBitRateKey : 320000,
    AVNumberOfChannelsKey: 2,
    AVSampleRateKey : 44100.0
]

I also got this error message trying to initialise an array of optionals with nil:

var eggs : [Egg] = Array<Egg>(count: 10, repeatedValue: nil)

Expression Type 'Array<Egg>' is ambiguous without more context.

Changing [Egg] to [Egg?] fixed the error.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!