Post

Replies

Boosts

Views

Activity

Is this correct way to use CoreData with the swiftUI 2.0 @main app protocol
Is this the correct way to to use coredata with the new App protocol? My app works like this but im a beginner so dont know if this is making some bad performance or if the app will crash in future when the coredata model get more entrys? See down: ContentView is the navigation menu, and the views i navigate to from contentview can use the coredata through the @Environment of managedObjectContext now so it seems like all is working.. import SwiftUI import CoreData @main struct TestApp: App {     var body: some Scene {         WindowGroup {             ContentView()                 .environment(\.managedObjectContext, persistentContainer.viewContext)                                  }     }     var persistentContainer: NSPersistentContainer = {                 let container = NSPersistentContainer(name: "TestApp")                 container.loadPersistentStores(completionHandler: { (storeDescription, error) in                     if let error = error as NSError? {                         fatalError("Unresolved error \(error), \(error.userInfo)")                     }                 })                 return container             }()             func saveContext() {                 let context = persistentContainer.viewContext                 if context.hasChanges {                     do {                         try context.save()                     } catch {                         let nserror = error as NSError                         fatalError("Unresolved error \(nserror), \(nserror.userInfo)")                     }                 }             } }
0
0
285
Jul ’20
Deleting a coredata item with custom button swiftUI
Im making a to do list app in the ios 14 sdk so swiftui 2.0. I cant use the list for the todo items because dont want the lines between items and it dont work with the animation i plan having when complete a task.. So i have made a LazyVStack inside a scrollview. and when press i press the text of the todo item the item toggle to my custom edit mode with a trashcan icon. the .onDelete seems to only work on a List with the built in swipe to delete or editbutton... anyone have any idea how i can delete the item stored in coredata when pressing a button?
0
0
633
Jul ’20