如何解决expression式的types在swift 2中没有更多的上下文

我已经升级到Swift 2.0,当我尝试录制声音时,我完全无法理解这一点:

expression的types是不明确的,没有更多的上下文

var recordSettings

我该怎么办才能解决这个错误,更重要的是为什么呢?

  var recordSettings = [ AVFormatIDKey: kAudioFormatAppleLossless, AVEncoderAudioQualityKey : AVAudioQuality.Max.rawValue, AVEncoderBitRateKey : 320000, AVNumberOfChannelsKey: 2, AVSampleRateKey : 44100.0 ] var dirPaths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true) var docsDir: AnyObject = dirPaths[0] var soundFilePath = docsDir.stringByAppendingPathComponent("tempRecordzz") var soundFileURL:NSURL = NSURL(fileURLWithPath: soundFilePath) var error: NSError? do { recorder = try AVAudioRecorder(URL: soundFileURL, settings: recordSettings) } catch var error1 as NSError { error = error1 recorder = nil } 

在Swift 7.0.1中, kAudioFormatAppleLossless的types从Int (Swift 1.2 / Xcode 6.4)更改为Int32 (Swift 2 / Xcode 7)和UInt32固定大小的整数types,如Int32UInt32 不会自动桥接到NSNumber对象插入NSDictionary

明确的转换有助于解决问题:

 let recordSettings = [ AVFormatIDKey: Int(kAudioFormatAppleLossless), // <-- HERE AVEncoderAudioQualityKey : AVAudioQuality.Max.rawValue, AVEncoderBitRateKey : 320000, AVNumberOfChannelsKey: 2, AVSampleRateKey : 44100.0 ]