TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

Basic CoreData problems in my training app - can you help please?

Forums > SwiftUI

Hi, according to Ultimate Portfolio app I have tried to make own small project. It is just database of shops and categories. Even if I went through manual several time, I still have two problems. First is when I click on button Delete Data, view Shops updates just when I turn off / on app. Second is when click on Vopi shop and delete Category by swipe left it makes temporary New Category. Last one is when I click on + , I have to go back to shops then back and category is there. Could you help mi please? Here is my project: http://www.internetstream.cz/transfer/shops.zip

2      

hi Jiří,

i can help with the second and the third problems:

Second is when click on Vopi shop and delete Category by swipe left it makes temporary New Category. Last one is when I click on + , I have to go back to shops then back and category is there.

in your CategoriesView, you have let shop: Shop, but you should instead have

@ObservedObject var shop: Shop

i'll continue to look at solving the first problem involving batch deletions on its own, although Shop deletions can certainly be solved by writing this

        let fetchRequest: NSFetchRequest<Shop> = Shop.fetchRequest()
        do {
            let shops = try container.viewContext.fetch(fetchRequest)
            for shop in shops {
                delete(shop)
            }
        } catch let error as NSError {
            print("Error: \(error.localizedDescription)")
        }

and the same would work for Categories (although if you mark the Delete rule for Shop.categories as "Cascade," all categories would as well be deleted just by running the code above).

hope that helps,

DMG

2      

Thanks a lot DMG, so "stupid" beginner mistake :-) Have a great day! Jiri

2      

Hacking with Swift is sponsored by Blaze.

SPONSORED Still waiting on your CI build? Speed it up ~3x with Blaze - change one line, pay less, keep your existing GitHub workflows. First 25 HWS readers to use code HACKING at checkout get 50% off the first year. Try it now for free!

Reserve your spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.