gpt4 book ai didi

swift - 错误 "Value of type ' String' has no member 'URLbyAppending' "with my Record Function

转载 作者:行者123 更新时间:2023-11-28 13:01:30 31 4
gpt4 key购买 nike

我的录音功能出现错误...它说“‘String’类型的值没有成员‘URLbyAppending’”

    func startRecording() {
let audioFilename = getDocumentsDirectory().URLbyAppending("recording.m4a")
let audioURL = NSURL(fileURLWithPath: audioFilename)

let settings = [
AVFormatIDKey: Int(kAudioFormatMPEG4AAC),
AVSampleRateKey: 12000.0,
AVNumberOfChannelsKey: 1 as NSNumber,
AVEncoderAudioQualityKey: AVAudioQuality.High.rawValue
]

这很烦人,因为在我的 Xcode 6 之前它工作得很好......

我需要一些帮助......谢谢

编辑

这是我的 getDocumentsDirectory 函数

    func getDocumentsDirectory() -> String {
let paths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)
let documentsDirectory = paths[0]
return documentsDirectory

最佳答案

您应该包含的 getDocumentsDirectory 函数显然返回一个字符串,而不是 URL。使用 stringByAppendingPathComponent 修复它。

或者,您可以更改 getDocumentsDirectory 函数以直接返回 url 并将调用更改为:

func getDocumentsDirectory() throws -> NSURL {
return try NSFileManager.defaultManager().URLForDirectory(.DocumentDirectory, inDomain: .UserDomainMask, appropriateForURL: nil, create: true)
}

let audioUrl = try getDocumentsDirectory().URLByAppendingPathComponent("recording.m4a")

请注意,由于 getDocumentsDirectory 可以抛出(URLForDirectory 可以抛出)getDocumentsDirectory 必须用 try 调用。

关于swift - 错误 "Value of type ' String' has no member 'URLbyAppending' "with my Record Function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33710449/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com