title: Using Core Data with SwiftUI
body: <p>I'm making progress learning SwiftUI but I'm getting stuck when it comes to using it with Core Data.</p>
  <ul>
  <li>Model Objects - I made a couple of entities with the required properties and relationships</li>
  <li>??? I have no idea where to begin. How to I get SwiftUI talking to Core Data?</li>
  <li>SwiftUI - I have some basic layouts working and showing data from some temp classes, but these have no awareness of Core Data</li>
  </ul>
  <p>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.</p>
  <p>Can anyone outline the basic steps to using Core Data with SwiftUI?</p>
  <h2>Update:</h2>
  <p>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: <a href="https://twitter.com/numist/status/1141012785825845248" rel="noreferrer">https://twitter.com/numist/status/1141012785825845248</a></p>
  <p>Here is the approach I'm going to take in my app.</p>
  <ul>
  <li>List Views:
  <ul>
  <li>UITableViewController (with a FetchedResultsController)</li>
  <li>Manage the connection to Core Data store</li>
  <li>Use dependency injection to pass records to a detail view</li>
  </ul>
  </li>
  <li>Detail / Edit Views:
  <ul>
  <li>When possible build these with UIHostingController</li>
  <li>Use SwiftUI Forms to make simple data entry forms</li>
  <li>Receive data via dependency injection</li>
  <li>Copy data to a temporary BindableObject type
  <ul>
  <li>Make local UI chances to the temp record</li>
  <li>Save the temp data back to the actual record on exit</li>
  </ul>
  </li>
  </ul>
  </li>
  </ul>
  <h2>Update 2 - 2019.08.14</h2>
  <p>Xcode beta 5 has some new Core Data features. I used the information in this <a href="https://www.andrewcbancroft.com/blog/ios-development/data-persistence/using-core-data-with-swiftui-introduction/" rel="noreferrer">blog post</a> to get most of what I need.</p>