用Alamofire下载后如何得到部分文件path?

我想保存下载文件到我的模型对象的path。 基于这个StackOverflow的答案 ,我应该“只存储文件名,然后结合它的文档目录的位置在飞行”。 那么在我的情况下,这是应用程序支持目录。 我不知道如何做到这一点。

下载文件的完整path是: /Library/ApplicationSupport/com.Company.DemoApp/MainFolder/myFile.jpg

/Library/Application Support/是我无法保存在任何地方的部分,我必须在运行时从FileManager获取它。

com.Company.DemoApp/MainFolder/myFile.jpg是我可以存储在数据库/configuration文件中的文件path的一部分。

但是我不知道如何从Alamofire下载它后得到这个path: com.Company.DemoApp/MainFolder/myFile.jpg 。 例如,这里是下载文件的代码,我如何得到这个path?

 func destination(named name: String, pathExtension: String) -> DownloadRequest.DownloadFileDestination { let destination: DownloadRequest.DownloadFileDestination = { _, _ in let appSupportDirURL = FileManager.createOrFindApplicationSupportDirectory() let fileURL = appSupportDirURL?.appendingPathComponent("com.Company.DemoApp/MainFolder/\(name).\(pathExtension)") return (fileURL!, [.removePreviousFile, .createIntermediateDirectories]) } return destination } let finalDestination = destination(named: image.title, pathExtension: image.preview.pathExtension) Alamofire.download(urlString, to: finalDestination).response { response in if let imagePath = response.destinationURL?.path { /// I want to this path here: com.Company.DemoApp/MainFolder/myFile.jpg /// But not sure how to get it. How do I get this path? } } 

问题是Alamofire给出了完整path: /Library/ApplicationSupport/com.Company.DemoApp/MainFolder/myFile.jpg 。 但是我只想要这个部分: com.Company.DemoApp/MainFolder/myFile.jpg

任何想法如何得到这条道路?

此外,如果您想在运行时获取文件,Apple似乎会参考Bookmark : Apple Docs for Bookmarks

请注意,这是前一个问题的后续操作。

更新1

这是我认为这可能工作的一种方式。 (根据上面的答案)。

 enum DataDirectory: String { case feed = "com.Compnay.DemoApp/MainFolder/" } Alamofire.download(urlString, to: finalDestination).response { response in let destURL = response.destinationURL! /// One way to save this path is to do so like this: myImageObject.partialLocalPath = "\(DataDirectory.feed.rawValue)\(destURL.lastPathComponent)" } } 

所以我将这个部分保存在一个enum并在下载完成后为其添加name – 然后将其添加到我的模型对象中进行保存。

有什么想法吗?