【发布时间】:2014-09-08 16:02:51
【问题描述】:
我尝试将这个 obj-c 代码翻译成 swift 代码:
NSDictionary *settings = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithFloat: 44100.0], AVSampleRateKey,
[NSNumber numberWithInt: kAudioFormatAppleLossless], AVFormatIDKey,
[NSNumber numberWithInt: 2], AVNumberOfChannelsKey,
[NSNumber numberWithInt: AVAudioQualityMax], AVEncoderAudioQualityKey,
nil];
// 迅速
var settings = [NSNumber.numberWithFloat(Float(44100.0)): AVSampleRateKey,
NSNumber.numberWithInt(Int32(kAudioFormatAppleLossless)): AVFormatIDKey,
NSNumber.numberWithInt(2): AVNumberOfChannelsKey,
NSNumber.numberWithInt(Int32(AVAudioQuality.Max)): AVEncoderAudioQualityKey];
但我收到错误:Type () 不符合协议“FloatLiteralConvertible”
有人知道如何纠正吗?谢了
【问题讨论】:
-
错误信息有误导性,使用NSNumber.numberWithInt(Int32(AVAudioQuality.Max.toRaw()))。
标签: dictionary compiler-errors swift ios8