I got the same error for (I think) another reason. In my model class I have a struct attribute with all optional fields, that is init with every field as nil. THIS PART IS CRAZY but apparently @Model transforms a struct with all nil fields into nil itself (I checked and this isn’t Swift behavior), this is obviously an issue if the struct field of the class isn’t optional hence the Passed nil for a non-optional keypath error. I fixed it at first by just making the struct attribute optional which sucks because it complicates the code to nil check the struct field everywhere, but now that I’ve realized the behavior I just gave the struct a dummy non-optional field.
Topic:
Developer Tools & Services
SubTopic:
Xcode
Tags: