Skip to content

Commit

Permalink
实时保存数据库
Browse files Browse the repository at this point in the history
  • Loading branch information
kingslay committed Oct 20, 2023
1 parent 65d18e8 commit 8ca1f88
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions Demo/SwiftUI/Shared/MovieModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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] {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 8ca1f88

Please sign in to comment.