title: Mock Core Data object in SwiftUI Preview
body: <p>Xcode's preview canvas keeps on crashing with no error message when I try to pass in a preview Core Data object like so:</p>
  <pre class="lang-swift prettyprint-override"><code>import SwiftUI
  import CoreData
  
  struct BookView: View {
      let book: Book
      
      var body: some View {
          Text(&quot;Hello, World!&quot;)
      }
  }
  
  // ^^^ This stuff is fine ^^^
  
  // vvv This stuff is not vvv
  
  struct BookView_Previews: PreviewProvider {
      static let moc = NSManagedObjectContext(concurrencyType: .mainQueueConcurrencyType)
      
      static var previews: some View {
          let book = Book(context: moc)
          book.title = &quot;Test book&quot;
          book.author = &quot;Test author&quot;
          book.genre = &quot;Fantasy&quot;
          book.rating = 4
          book.review = &quot;This was a great book; I really enjoyed it.&quot;
          
          return NavigationView {
              BookView(book: book)
          }
      }
  }
  </code></pre>
  <p>I'm following a Hacking with Swift tutorial on Core Data and SwiftUI and am at <a href="https://www.hackingwithswift.com/books/ios-swiftui/showing-book-details" rel="nofollow noreferrer">this step</a>.</p>
  <p>This appears to be the standard way to add preview objects into the SwiftUI canvas, but I'm unable to get it to work. FYI the app runs fine in the simulator, I'm just trying to get it to also work in the preview canvas. I'm using Xcode 13.2.1 on macOS 12.</p>
  <p>Thank you!</p>