---
title: "Discussion on \"SwiftPM中使用CoreData在SwiftUI进行Preview的小纸条\" | Hashnode"
description: "Discussion on \"SwiftPM中使用CoreData在SwiftUI进行Preview的小纸条\". 使用SwiftPM重构英语小助手一段时间了，遇到了一个问题，就是在SwiftUI里使用一个在SwiftPM中定义的CoreData时，如果进行Preview就会直接挂掉。这是它的提示信息：\n\n如果点Preview中的Diagnostics按钮会得到这样的信息：\n\n这是我在CoreData中对于加载数据的定义代码：\nclass PersistentContainer: NSPersistentContainer {\n    init(name: String, bundle: Bundle = ...."
url: "https://hashnode.com/posts/swiftpm-coredata-swiftui-preview-fixed/623d354b2209c88a3de8f121"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [SwiftPM中使用CoreData在SwiftUI进行Preview的小纸条](https://blog.hdcola.org/swiftpm-coredata-swiftui-preview-fixed?utm_source=hashnode&utm_medium=feed)

使用SwiftPM重构英语小助手一段时间了，遇到了一个问题，就是在SwiftUI里使用一个在SwiftPM中定义的CoreData时，如果进行Preview就会直接挂掉。这是它的提示信息： 如果点Preview中的Diagnostics按钮会得到这样的信息： 这是我在CoreData中对于加载数据的定义代码： class PersistentContainer: NSPersistentContainer { init(name: String, bundle: Bundle = ....

Mar 25, 2022 · 2 min read · blog.hdcola.org  
Read the article

-   [#xcode](https://hashnode.com/tag/xcode)
-   [#swift](https://hashnode.com/tag/swift)

## Written by

[老房东](https://hashnode.com/@hdcola)

@hdcola · Quebec CA

  
[View profile](https://hashnode.com/@hdcola)

Let's enjoy life

## Responses

Markdown supported · ⌘↵ to post

No responses yet.
