diff GeoQuiz/Logic/CoreDataController.swift @ 19:f140bb277c96

refactor code
author Dennis C. M. <dennis@denniscm.com>
date Sun, 23 Oct 2022 00:11:38 +0100
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/GeoQuiz/Logic/CoreDataController.swift	Sun Oct 23 00:11:38 2022 +0100
@@ -0,0 +1,21 @@
+//
+//  CoreDataController.swift
+//  GeoQuiz
+//
+//  Created by Dennis Concepción Martín on 22/10/22.
+//
+
+import Foundation
+import SwiftUI
+import CoreData
+
+class CoreDataController {
+    static func deleteGame(at offsets: IndexSet, from games: FetchedResults<PlayedGame>, with moc: NSManagedObjectContext) {
+        for offset in offsets {
+            let game = games[offset]
+            moc.delete(game)
+        }
+        
+        try? moc.save()
+    }
+}