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