Swift - 如何知道文件是否成功保存在 .cachesDirectory 中

Swift -How to know if a file was successfully saved in .cachesDirectory

我在 Firebase 中保存了一个 .mp4 视频,我想将它保存到 .cachesDirectory。我想确保它已保存并尝试使用 do-try 块,但它不接受它:

No calls to throwing functions occur within 'try' expression.

我还能如何检查文件是否已成功保存到 .cachesDirectory

let fbStr = "https://firebasestorage.googleapis.com/v0/b/myApp.appspot.com/o/abcd%277920FHqFBkl7D6j%2F-MC65EFG_qT0KZbdtFhU%2F48127-8C29-4666-96C9-E95BE178B268.mp4?alt=media&token=bf85dcd1-8cee-428e-87bc-91800b7316de"
guard let url = URL(string: fbStr) else { return }
let videoData = NSData(contentsOf: url)
let cachesDir = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask).first!

do {
    try videoData?.write(toFile: cachesDir.path, atomically: true)
} catch {
    print("video wasn't saved to cachesDirectory") 
}

使用不带 automically 参数的 write(toFile:) 方法。

do {
    try videoData?.write(toFile: cachesDir.path, options: .atomic)
} catch {
    print("video wasn't saved to cachesDirectory")
}