I'm making progress learning SwiftUI but I'm getting stuck when it comes to using it with Core Data.
- Model Objects - I made a couple of entities with the required properties and relationships
- ??? I have no idea where to begin. How to I get SwiftUI talking to Core Data?
- SwiftUI - I have some basic layouts working and showing data from some temp classes, but these have no awareness of Core Data
I've spend the last few days searching and reading everything I can on this topic but I have no idea how to begin to solve this.
Can anyone outline the basic steps to using Core Data with SwiftUI?
Update:
I got some additional feedback on Twitter and one dev suggested that SwiftUI lists may not be suitable for working with Core Data with large data sets. Read the post here: https://twitter.com/numist/status/1141012785825845248
Here is the approach I'm going to take in my app.
- List Views:
- UITableViewController (with a FetchedResultsController)
- Manage the connection to Core Data store
- Use dependency injection to pass records to a detail view
- Detail / Edit Views:
- When possible build these with UIHostingController
- Use SwiftUI Forms to make simple data entry forms
- Receive data via dependency injection
- Copy data to a temporary BindableObject type
- Make local UI chances to the temp record
- Save the temp data back to the actual record on exit
Update 2 - 2019.08.14
Xcode beta 5 has some new Core Data features. I used the information in this blog post to get most of what I need.