From ad4483aa636546053c8bdd569b961379a35f6aa6 Mon Sep 17 00:00:00 2001 From: Ilyas Hallak Date: Wed, 25 Jun 2025 21:43:32 +0200 Subject: [PATCH] wip --- readeck/Data/Persistence.swift | 57 ------------ .../Domain/UseCase/SyncBookmarksUseCase.swift | 0 readeck/UI/ContentView.swift | 88 ------------------- 3 files changed, 145 deletions(-) delete mode 100644 readeck/Data/Persistence.swift create mode 100644 readeck/Domain/UseCase/SyncBookmarksUseCase.swift delete mode 100644 readeck/UI/ContentView.swift diff --git a/readeck/Data/Persistence.swift b/readeck/Data/Persistence.swift deleted file mode 100644 index 01c23eb..0000000 --- a/readeck/Data/Persistence.swift +++ /dev/null @@ -1,57 +0,0 @@ -// -// Persistence.swift -// readeck -// -// Created by Ilyas Hallak on 10.06.25. -// - -import CoreData - -struct PersistenceController { - static let shared = PersistenceController() - - @MainActor - static let preview: PersistenceController = { - let result = PersistenceController(inMemory: true) - let viewContext = result.container.viewContext - for _ in 0..<10 { - let newItem = Item(context: viewContext) - newItem.timestamp = Date() - } - do { - try viewContext.save() - } catch { - // Replace this implementation with code to handle the error appropriately. - // fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. - let nsError = error as NSError - fatalError("Unresolved error \(nsError), \(nsError.userInfo)") - } - return result - }() - - let container: NSPersistentContainer - - init(inMemory: Bool = false) { - container = NSPersistentContainer(name: "readeck") - if inMemory { - container.persistentStoreDescriptions.first!.url = URL(fileURLWithPath: "/dev/null") - } - container.loadPersistentStores(completionHandler: { (storeDescription, error) in - if let error = error as NSError? { - // Replace this implementation with code to handle the error appropriately. - // fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. - - /* - Typical reasons for an error here include: - * The parent directory does not exist, cannot be created, or disallows writing. - * The persistent store is not accessible, due to permissions or data protection when the device is locked. - * The device is out of space. - * The store could not be migrated to the current model version. - Check the error message to determine what the actual problem was. - */ - fatalError("Unresolved error \(error), \(error.userInfo)") - } - }) - container.viewContext.automaticallyMergesChangesFromParent = true - } -} diff --git a/readeck/Domain/UseCase/SyncBookmarksUseCase.swift b/readeck/Domain/UseCase/SyncBookmarksUseCase.swift new file mode 100644 index 0000000..e69de29 diff --git a/readeck/UI/ContentView.swift b/readeck/UI/ContentView.swift deleted file mode 100644 index 4211012..0000000 --- a/readeck/UI/ContentView.swift +++ /dev/null @@ -1,88 +0,0 @@ -// -// ContentView.swift -// readeck -// -// Created by Ilyas Hallak on 10.06.25. -// - -import SwiftUI -import CoreData - -struct ContentView: View { - @Environment(\.managedObjectContext) private var viewContext - - @FetchRequest( - sortDescriptors: [NSSortDescriptor(keyPath: \Item.timestamp, ascending: true)], - animation: .default) - private var items: FetchedResults - - var body: some View { - NavigationView { - List { - ForEach(items) { item in - NavigationLink { - Text("Item at \(item.timestamp!, formatter: itemFormatter)") - } label: { - Text(item.timestamp!, formatter: itemFormatter) - } - } - .onDelete(perform: deleteItems) - } - .toolbar { -#if os(iOS) - ToolbarItem(placement: .navigationBarTrailing) { - EditButton() - } -#endif - ToolbarItem { - Button(action: addItem) { - Label("Add Item", systemImage: "plus") - } - } - } - Text("Select an item") - } - } - - private func addItem() { - withAnimation { - let newItem = Item(context: viewContext) - newItem.timestamp = Date() - - do { - try viewContext.save() - } catch { - // Replace this implementation with code to handle the error appropriately. - // fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. - let nsError = error as NSError - fatalError("Unresolved error \(nsError), \(nsError.userInfo)") - } - } - } - - private func deleteItems(offsets: IndexSet) { - withAnimation { - offsets.map { items[$0] }.forEach(viewContext.delete) - - do { - try viewContext.save() - } catch { - // Replace this implementation with code to handle the error appropriately. - // fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. - let nsError = error as NSError - fatalError("Unresolved error \(nsError), \(nsError.userInfo)") - } - } - } -} - -private let itemFormatter: DateFormatter = { - let formatter = DateFormatter() - formatter.dateStyle = .short - formatter.timeStyle = .medium - return formatter -}() - -#Preview { - ContentView().environment(\.managedObjectContext, PersistenceController.preview.container.viewContext) -}