Reputation: 149
This code snippet worked with swift but does not compile with swift2.
let settings = [
AVFormatIDKey: kAudioFormatLinearPCM,
AVSampleRateKey: 44100.0,
AVNumberOfChannelsKey: 1,
AVLinearPCMBitDepthKey: 16,
AVLinearPCMIsBigEndianKey: true
]
let audioFile = AVAudioFile(forWriting:url, settings:settings, error:&error)
I get a "Type of expression is ambiguous without more context" error. If i change the assignment to [String : Any] i get a error at AVAudioFile because it expects a [String : AnyObject] array.
let settings:[String : Any] = [
AVFormatIDKey: kAudioFormatLinearPCM,
AVSampleRateKey: 44100.0,
AVNumberOfChannelsKey: 1,
AVLinearPCMBitDepthKey: 16,
AVLinearPCMIsBigEndianKey: true
]
let audioFile = try! AVAudioFile(forWriting:url, settings:settings)
Does anyone know how to create [String : AnyObject] array in swift2?
Upvotes: 2
Views: 588
Reputation: 70098
kAudioFormatLinearPCM
was an UInt32 but Swift 2 wants an Int instead:
let settings: [String:AnyObject] = [
AVFormatIDKey: Int(kAudioFormatLinearPCM),
AVSampleRateKey: 44100.0,
AVNumberOfChannelsKey: 1,
AVLinearPCMBitDepthKey: 16,
AVLinearPCMIsBigEndianKey: true
]
Upvotes: 4