|
I am trying to filter a list with a search bar and only have those sections and data under those sections in the filtered list when I search for a hymn. Here is my struct, my computed property that sorts everything for me into the right sections. If I add the filter to the ForEach loop on the hymns it leaves section headers with no data and it just looks horrible. Can someone help me with this? Struct I use that models my JSON File JSONModel Struct
How I am sorting the data (Computed Property)
How can I filter the list on hymn and leave only the hymns and headers that are left. I took out my filter I had on the foreach for hymns. I thought it would be easier for you guys to see.
Thanks, Mark |
|
hi Mark, the
my suggested function
now, however, you need a better setup for the List to provide only those sections of interest. my suggestion would be this,
hope that helps, DMG |
|
Hi DMG, Thank you for the help. I appreciate that. I will give this a try. Now I have a question out on this forum about error checking with CoreData. Do you know how to do this? They put in boiler plate code and user fatal error and then tell us not to use it. So my question is how do we error check correctly when performing a do/try catch block when saving or creating or deleting a new record. Thanks Mark |
|
Mark, i saw your previous question about Core Data Error Checking and was hoping someone else might pick up on this, only because handling an error in startup with Core Data is a tricky problem. perhaps showing an Alert with the error message is the best you can do before closing the program. i have not done anything on the startup issue. but i will somewhat tackle your more specific question
creating, editing, or deleting a CD object does not generate an error itself, but the concern is in saving the context. a lot of Hudson's code would either
the old AppDelegate code (some of which appears in the new Persistence.swift file that defines a singleton
so i follow up all changes to core data objects simply with the equivalent of that may not be the answer you were searching for; and i am sure that the situation gets more complicated if you use NSPersistentCloudKitContainer. i expect i'll start finding this out as my next project is hooking up to the cloud. good luck, DMG |
|
Hi DMG, I'm not sure what you mean or how to do what you suggested below?
Thanks, Mark |
|
Mark, sorry for any confusion. you have three choices once you add, edit, or delete a CD object: (1) you finish by writing the one-liner
if there's an error, you don't know about it. but if you're in the middle of development, you really do need to know about errors. the most common one is that you open a sheet and use this code, but don't realize that the CD environment was never passed to the sheet and the value of the context variable (2) you finish by writing the same, five-line generic do/try/catch block
you'll get tired of doing this. (3) you finish by writing the one-liner
where the error is logged, assuming the PersistenceController has the code i suggested above to catch the error and log it. hope that helps, DMG |
TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!
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.