我已经实现了Core Data来保存我的应用程序中的字符串格式化的URL . 这些URL是他们录制的视频的URL .

我使用核心数据是因为我希望视频在退出应用后仍可供他们使用 . 我能够保存和检索URLS . 但是,当我使用它们来获取视频缩略图时,它不起作用 .

这是我声明视频文件位置的地方:

let documentsPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] as NSString
    let cropUniqueId = NSUUID().uuidString
    let outputPath = "\(documentsPath)/\(cropUniqueId).mov"

然后我将其转换为字符串并将数据保存到核心数据:

arrayOfStringPaths.append(outputPath)
    stringOfArrayPaths = stringOfArrayPaths + arrayOfStringPaths.joined(separator: ",")
    saveData(arrayPath: stringOfArrayPaths)



 func saveData(arrayPath: String) {

    let savedVideo = VideoPath(context: context)
    savedVideo.fileLocations = arrayPath
    appDelegate.saveContext()
    print("Saved")

}

到目前为止一切都很好 . 它保存了URL,就像它们一样,我用各种打印语句检查它们 .

现在,当用户打开应用程序时,我会检索信息 .

var data = [VideoPath]()

    func fetchSavedData() {
    do {
        data = try context.fetch(VideoPath.fetchRequest())


        for each in data {
            // I append each url to the array. 
            videosArray.append(URL(fileURLWithPath: each.fileLocations!))

            // They all print out correctly 
            print(each.fileLocations!)
        }

        for video in videosArray {
            print("This is in video array")
            // This prints out correctly as the URL i recorded earlier
            print(video) 

            // This is where everything messes up
            let thumbnail = getThumbnail(video)
            thumbnails.append(thumbnail)

        }

    } catch {
        print("There was an error")
    }

}

当我尝试获取视频的缩略图时,它在这里给我这个错误:

“在此服务器上找不到请求的URL . ” UserInfo = {NSLocalizedDescription =在此服务器上找不到请求的URL . ,NSUnderlyingError = 0x17064c330 {错误域= NSPOSIXErrorDomain代码= 2“没有这样的文件或目录”}}:file /Library/Caches/com.apple.xbs/Sources /swiftlang/swiftlang-802.0.53/src/swift/stdlib/public/core/ErrorType.swift