Use SwiftData Crash When #Preview

the Model Code

import Foundation
import SwiftData

@Model
class TestItemTotal {
    var id = UUID()
    var name: String
    var describe: String
    init(name: String = "", describe: String = "") {
        self.name = name
        self.describe = describe
    }
}

the contentView code

import SwiftUI

class ShareData: ObservableObject {
    @Published var path: NavigationPath = NavigationPath()
    @Published var selectedTestItemTotal = TestItemTotal()
}

struct ContentView: View {
    @StateObject var shareData = ShareData()
    
    var body: some View {
        NavigationStack(path: $shareData.path) {
            List{
                Text("The Main Project List")
                Text("The Detail List")
            }
        }
    }
    
}

#Preview {
    ContentView()
}

Crash

it will crash ,when #preview use Xcode , but it will not crash when run in Simulator .

fix Crash

Remove @Model string , it will not crash , when #preview use Xcode , but i can't remove @Model String , because i will to processing data by SwiftData

What is the crash? Saying something has crashed without the specifics of the crash is most likely not going to get you the help you're looking for. So provide any logs you may have related to the crash from the Xcode console or a screenshot of the crash so anyone looking at your post can have a context to work with.

the crash info

the follow is crash photo

Use SwiftData Crash When #Preview
 
 
Q