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

lernerbot picture lernerbot · Sep 19, 2015 · Viewed 51k times · Source

The following used to work in Swift 1.2:

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

Now, it gives the error:

"Type expression is ambiguous without more context".

Answer

Unheilig picture Unheilig · Sep 19, 2015

You could give the compiler more information:

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