|
Hi! I'm on day 59 and currently work with the filtered list that I've created in Day 58, part 2. I did everything according to the tutorial but also decided to implement deletion and that's the part where I encountered a problem. There are 3 singers. I use a predicate "A" to show singers whose last name starts with the letter A and "S" for those whose last name starts with the letter "S". So the singers on the screen, I choose predicate "S", and the list shows me 2 objects. I delete them. no problem at all. After that, I choose the predicate "A" and the last singer is presented now. When I delete this singer - another one (like a ghost) appears. I don't know how Swift gives it a name and last name, because when I check it with I've got 2 swift files: ContentView:
And ListOfSingers:
I don't even understand why is it happening. I check the number of elements in the array after deletion and it says 0. If it's 0, how the singer is shown in the List if it doesn't exist in the array that is used to populate the List <emoji head explosion> Thanks for your help guys! |
|
Change your delete function to this and have a try: func deleteSinger(at offsets: IndexSet) {
|
|
|
|
I came back here after more than a month a came up with this: The problem was that for some reason ListOfSingers struct was called twice. Even though I've deleted the last singer from Core Data the render time was faster than reindexing of Core Data. So I ended up having a "Ghost View", which was rendered before I item was fully deleted from the Core Data. When I tried to delete a Ghost View I was reaching an array that didn't exist. It always lead to an app crash. The solution was to add a function that checked if there are any items in Core Data right after deletion fired off. 1) Create
2) Add a 3) Add function to Persistanse Controller to get all items:
4) Add function to
Now everything works! |
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.
Sponsor Hacking with Swift and reach the world's largest Swift community!
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.
Link copied to your pasteboard.