|
Total beginner here. Warning: this might be a long post, sorry! I've been following along with the excellent tutorials and articles on this site and I feel that I'm getting somewhat of a tentative grip on SwiftUI. I'm very much still learning and thought I would ask this excellent community for help with my next step. Now to my issue: I want to create an iOS app, where the user can create categories and then add items to those categories (Category 1, Category 2, etc.). I want those items to be shown in a list that uses one or more pieces of data to dynamically group the items together (Category 1 : Group 1, Category 1 : Group 2, etc.). I then want to show the groups content in a new list. (Category 1 : Group 1: Item 1...n) Perhaps an image will explain it better: Link to image on Google Drive How can I achieve this? I've tried modifying the Bookworm project as well as following along with the Core Data tutorials, but I can't quite understand how to achieve what I want. Example of user flow:
Does this make sense? Is this achievable with SwiftUI and something like Core Data? |
|
Yes, this is definitely possible with SwiftUI. Your image was really helpful and makes me think you've already got a good idea of the data schema you want to use. If you haven't already I strongly recommend you watch the Data Essentials in SwiftUI video here: https://developer.apple.com/videos/play/wwdc2020/10040/ This has great advice about how to think about SwiftUI views that you create: What data does this view need? How will it use the data? Where does the data come from? If you break down your problem along those lines things will become simpler to reason about. For example, from your image you require 4 views, something like |
|
@lordmooch Thanks! I'll have a look at the link you provided. My view setup is pretty much what you described already, so I'm happy to see that I was on the right track. Now I just need to figure out the Core Data aspect of it all. Would you say that I need to use relationships in Core Data for this to work out the way I want, or could I solve it some other way? With filtered data perhaps? Thanks again for taking the time to respond! Super helpful. |
|
hi, @lordmooch has the view setup right. the Core Data setup is similar: Entity Category <-- one to many -->> Entity Group <-- one to many -->> Entity Item to match the views with the data:
be sure you know how to read the relationship objects from Core Data. for example, if Category has a one to many relationship to Group named
you can read how many groups there are for a category with
one last thing: the names hope that helps, DMG |
|
@delawaremathguy That was super helpful! Thanks so much for taking the time to answer my question in such a detailed manner. |
|
I have no experience with Core Data as I have never used it, so I don't want to comment on that specifically. More generally, I am an advocate of letting the persistence layer protect you from data errors. So I would use relationships and so on to ensure that the data can't be (famous last words!) corrupted no matter what happens in the UI. I think @delawaremathguy has the right idea with the relationships he defined earlier. |
|
SPONSORED Alex is the iOS & Mac developer’s ultimate AI assistant. It integrates with Xcode, offering a best-in-class Swift coding agent. Generate modern SwiftUI from images. Fast-apply suggestions from Claude 3.5 Sonnet, o3-mini, and DeepSeek R1. Autofix Swift 6 errors and warnings. And so much more. Start your 7-day free trial today!
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.