SwiftData Project crashes since beta 6

Hi folks,

I've seen multiple posts regarding this issue and wanted to throw down my two cents.

I've been having failed builds since beta 6, and I'm about to loose my mind :P My models used are defined in a Swift Package inside my project, and I have a screen that adds a new object to the modelContext.

  @Environment(\.modelContext) var modelContext
  @State var thought = Thought(date: .now, name: "", event: "", thought: "", feeling: Feeling(afraid: 0, angry: 0, sad: 0, ashamed: 0, happy: 0, neutral: 0), behaviour: "", effect: "", alternative: AltThought(thought: "", feeling: Feeling(afraid: 0, angry: 0, sad: 0, ashamed: 0, happy: 0, neutral: 0), behaviour: "", effect: ""))
  @State var feeling = Feeling(afraid: 0, angry: 0, sad: 0, ashamed: 0, happy: 0, neutral: 0)

  @State var alternativeThought = AltThought(thought: "", feeling: Feeling(afraid: 0, angry: 0, sad: 0, ashamed: 0, happy: 0, neutral: 0), behaviour: "", effect: "")
  @State var alternativeFeeling = Feeling(afraid: 0, angry: 0, sad: 0, ashamed: 0, happy: 0, neutral: 0)

Then in my view I have a Form where my users can edit the values. Prior to beta 6 this was working beautifully. Now I am experiencing failed build and I am getting the following stack trace:

Apple Swift version 5.9 (swiftlang-5.9.0.128.106 clang-1500.0.40.1)
2.	Compiling with the current language version
3.	While evaluating request TypeCheckSourceFileRequest(source_file "/Users/franksolleveld/Developer/AltoThought/App/Views/Thoughts/NewThoughtView.swift")
4.	While type-checking 'NewThoughtView' (at /Users/franksolleveld/Developer/AltoThought/App/Views/Thoughts/NewThoughtView.swift:13:1)
5.	While evaluating request StoredPropertiesRequest(AltoThought.(file).NewThoughtView@/Users/franksolleveld/Developer/AltoThought/App/Views/Thoughts/NewThoughtView.swift:13:8)
6.	While evaluating request PropertyWrapperInitializerInfoRequest(AltoThought.(file).NewThoughtView.thought@/Users/franksolleveld/Developer/AltoThought/App/Views/Thoughts/NewThoughtView.swift:17:16)
7.	While evaluating request PropertyWrapperBackingPropertyTypeRequest(AltoThought.(file).NewThoughtView.thought@/Users/franksolleveld/Developer/AltoThought/App/Views/Thoughts/NewThoughtView.swift:17:16)
8.	While evaluating request InterfaceTypeRequest(AltoThought.(file).NewThoughtView.thought@/Users/franksolleveld/Developer/AltoThought/App/Views/Thoughts/NewThoughtView.swift:17:16)
9.	While evaluating request NamingPatternRequest(AltoThought.(file).NewThoughtView.thought@/Users/franksolleveld/Developer/AltoThought/App/Views/Thoughts/NewThoughtView.swift:17:16)
10.	While evaluating request PatternBindingEntryRequest((unknown decl), 0, 0)
11.	While type-checking expression at [/Users/franksolleveld/Developer/AltoThought/App/Views/Thoughts/NewThoughtView.swift:17:6 - line:17:332] RangeText="State var thought = Thought(date: .now, name: "", event: "", thought: "", feeling: Feeling(afraid: 0, angry: 0, sad: 0, ashamed: 0, happy: 0, neutral: 0), behaviour: "", effect: "", alternative: AltThought(thought: "", feeling: Feeling(afraid: 0, angry: 0, sad: 0, ashamed: 0, happy: 0, neutral: 0), behaviour: "", effect: "")"
12.	While type-checking-target starting at /Users/franksolleveld/Developer/AltoThought/App/Views/Thoughts/NewThoughtView.swift:17:6
13.	While reading from module 'Thoughts', builder version '5.9(5.9)/Apple Swift version 5.9 (swiftlang-5.9.0.128.106 clang-1500.0.40.1)', built from source, non-resilient, loaded from '/Users/franksolleveld/Library/Developer/Xcode/DerivedData/AltoThought-atnarzndlkqvenclcdajpuljbqzf/Build/Products/Debug-iphoneos/Thoughts.swiftmodule/arm64-apple-ios.swiftmodule'
14.	While finishing conformance for protocol conformance to 'PersistentModel' (in module 'SwiftData') for type 'Feeling'
15.	*** DESERIALIZATION FAILURE ***

I submitted feedback FB12965130 but Apple marked it as Investigation Complete - Currently works as designed. So I'm assuming there's something I need to change in my view here to make it compile again.

What are your suggestions? Am I missing something? How could I have seen this coming? I tried reading the release notes but I might have been blind as I couldn't find anything that would cause this.

Any suggestions/feedback is welcome! Thanks in advance

Answered by SpaceMan in 764118022

I assume you've checked this post. Looks like packages are the culprit.

Also cleared DerivedData and made sure Feeling is a Model.

@Model
public class Feeling {
    public let id: UUID
    public var afraid: Int
    public var angry: Int
    public var sad: Int
    public var ashamed: Int
    public var happy: Int
    public var neutral: Int

    public init(afraid: Int, angry: Int, sad: Int, ashamed: Int, happy: Int, neutral: Int) {
        self.id = UUID()
        self.afraid = afraid
        self.angry = angry
        self.sad = sad
        self.ashamed = ashamed
        self.happy = happy
        self.neutral = neutral
    }
}

This is the Model Feeling that is causing issues apparently

Accepted Answer

I assume you've checked this post. Looks like packages are the culprit.

SwiftData Project crashes since beta 6
 
 
Q