无法将类型("字符串:字符串)"的值转换为预期的参数类型 'URL'



当我运行以下代码时,我收到错误cannot convert value of type ('string: String)' to expected argument type 'URL'

 var recorder = AVAudioRecorder(url: (string: URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("tmp.caf").absoluteString), settings: [
        AVFormatIDKey : Int(kAudioFormatAppleIMA4),
        AVSampleRateKey : Int(44100),
        AVNumberOfChannelsKey : Int(1),
        AVLinearPCMBitDepthKey : Int(16),
        AVLinearPCMIsBigEndianKey : false,
        AVLinearPCMIsFloatKey : false
        ])

这应该有效:

let recorder = AVAudioRecorder(url: URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("tmp.caf"), settings: [
            AVFormatIDKey : Int(kAudioFormatAppleIMA4),
            AVSampleRateKey : Int(44100),
            AVNumberOfChannelsKey : Int(1),
            AVLinearPCMBitDepthKey : Int(16),
            AVLinearPCMIsBigEndianKey : false,
            AVLinearPCMIsFloatKey : false
            ])

最新更新