UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Deleting an entity from an array in CoreData

Forums > SwiftUI

Hi guys, i am currently practicing some coredata exercise by making a flashcard app where the user would input words and their definitions into cards. I have set up a CardEntity with 'id', 'word' and 'definition' as its attributes, all of type String.

Now this is my View: https://imgur.com/3Mjhp93

and this is my function to delete a selected card which i declared in an observableObject class and apparently is not correct. How would i go to change the func to make it work?

func deleteCard(card: CardEntity) {
        if let selectedCard = cards.first(where: {$0.id == card.id}) {
            manager.context.delete(selectedCard)
        }
}

And when i applied this rather simple fuction then the text and definition got deleted but not the card background. Now it left me a blank card with no value on it

func deleteCard(card: CardEntity) {
        manager.context.delete(card)
        save()
    }

If you guys need some more code for more info, please let me know cuz i dont' want to annoy you guys with hundred lines of code

2      

Hacking with Swift is sponsored by Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.

Click to save your free 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.