gpt4 book ai didi

ios - 错误 : Value of type 'String' has no member 'URLByAppendingPathComponent'

转载 作者:搜寻专家 更新时间:2023-10-31 22:00:12 24 4
gpt4 key购买 nike

我的错误是:“String”类型的值没有成员“URLByAppendingPathComponent”

我在这一行中遇到了错误:

 let savePath = documentDirectory.URLByAppendingPathComponent("mergeVideo-\(date).mov")

我的完整代码:

  // 4 - Get path
let documentDirectory = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0]
var dateFormatter = NSDateFormatter()
dateFormatter.dateStyle = .LongStyle
dateFormatter.timeStyle = .ShortStyle
let date = dateFormatter.stringFromDate(NSDate())
let savePath = documentDirectory.URLByAppendingPathComponent("mergeVideo-\(date).mov")

let url = NSURL(fileURLWithPath: savePath)

我遵循了本教程:Here

最佳答案

let savePath = (documentDirectory as NSString).stringByAppendingPathComponent("mergeVideo-\(date).mov")

因为 documentDirectory 是一个 String 而不是 NSURL

编辑

我推荐使用这个 API:

let documentDirectory = try! NSFileManager.defaultManager().URLForDirectory(.DocumentDirectory, inDomain: .UserDomainMask, appropriateForURL: nil, create: false)
var dateFormatter = NSDateFormatter()
dateFormatter.dateStyle = .LongStyle
dateFormatter.timeStyle = .ShortStyle
let date = dateFormatter.stringFromDate(NSDate())
let saveURL = documentDirectory.URLByAppendingPathComponent("mergeVideo-\(date).mov") // now it's NSURL

swift 3+

let documentDirectory = try! FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false)
var dateFormatter = DateFormatter()
dateFormatter.dateStyle = .long
dateFormatter.timeStyle = .short
let date = dateFormatter.string(from: Date())
let saveURL = documentDirectory.appendingPathComponent("mergeVideo-\(date).mov")

关于ios - 错误 : Value of type 'String' has no member 'URLByAppendingPathComponent' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33787003/

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