Xcode swift 2字典含糊不清,没有更多的上下文
在从1.2转换到swift 2时,我遇到了一个错误,表达式的类型是不明确的,没有更多的上下文Xcode swift 2字典含糊不清,没有更多的上下文,xcode,swift,Xcode,Swift,在从1.2转换到swift 2时,我遇到了一个错误,表达式的类型是不明确的,没有更多的上下文 var recordSettings = [ AVFormatIDKey: kAudioFormatLinearPCM, AVSampleRateKey : 44100.0, AVNumberOfChannelsKey: 1, AVLinearPCMBitDepthKey : 32, AVLinearPCMI
var recordSettings = [
AVFormatIDKey: kAudioFormatLinearPCM,
AVSampleRateKey : 44100.0,
AVNumberOfChannelsKey: 1,
AVLinearPCMBitDepthKey : 32,
AVLinearPCMIsFloatKey : true
我不知道是什么问题。我试着用[String:AnyObject]来施法,但没有成功。非常感谢您的建议。类型推断器很难意识到
kaudioformlinearpcm
是UInt32
的别名,并且可以在NSNumber
中装箱
因此,帮助它:
var recordSettings:[String:AnyObject] = [
AVFormatIDKey: NSNumber(unsignedInt: kAudioFormatLinearPCM),
AVSampleRateKey : 44100.0,
AVNumberOfChannelsKey: 1,
AVLinearPCMBitDepthKey : 32,
AVLinearPCMIsFloatKey : true]