From 8ca1f889c7c3d2b7eaaac95d8838c0a870ba5b63 Mon Sep 17 00:00:00 2001 From: kintan Date: Fri, 20 Oct 2023 19:17:01 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E6=97=B6=E4=BF=9D=E5=AD=98=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Demo/SwiftUI/Shared/MovieModel.swift | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Demo/SwiftUI/Shared/MovieModel.swift b/Demo/SwiftUI/Shared/MovieModel.swift index a46eb6b1c..28cee4f1f 100644 --- a/Demo/SwiftUI/Shared/MovieModel.swift +++ b/Demo/SwiftUI/Shared/MovieModel.swift @@ -164,6 +164,11 @@ extension M3UModel { // let deleteRequest = NSBatchDeleteRequest(fetchRequest: movieRequest) // _ = try? context.execute(deleteRequest) } + do { + try context.save() + } catch { + KSLog(level: .error, error.localizedDescription) + } } func getMovieModels() async -> [MovieModel] { @@ -193,9 +198,7 @@ extension M3UModel { } let result = try await m3uURL.parsePlaylist() guard result.count > 0 else { - await viewContext.perform { - viewContext.delete(self) - } + delete() return [] } return await viewContext.perform { @@ -231,10 +234,10 @@ extension M3UModel { } viewContext.perform { if viewContext.hasChanges { - try? viewContext.save() for model in dic.values { viewContext.delete(model) } + try? viewContext.save() } } return models @@ -278,6 +281,7 @@ extension MovieModel { newMovieModel.setValuesForKeys(dictionaryWithValues(forKeys: entity.attributesByName.keys.map { $0 })) newMovieModel.playmodel = model context.assign(newMovieModel, to: privateStore) +// try? context.save() newMovieModel.save() context.delete(self) return model @@ -353,6 +357,8 @@ extension KSVideoPlayerView { } else { options.formatContextOptions["listen_timeout"] = 3 } + playmodel.save() + model.save() self.init(url: url, options: options, title: model.name) { layer in if let layer { playmodel.duration = Int16(layer.player.duration)