How to solve "No exact matches in call to instance method 'setValue'"
Make sure that the SwiftData variable conforms to the Codable protocol.


Make sure that the SwiftData variable conforms to the Codable protocol.
SubscribeCheck out our SwiftData Quick Start GuideProblem

When adding a complex value (i.e. a struct or enumeration) we encountered the following error:
"No exact matches in call to instance method 'setValue'"
- In expansion of macro '_PersistedProperty' here
- Candidate requires that '[complex_value]' conform to 'PersistentModel' (requirement specified as 'Value' : 'PersistentModel')
- Candidate requires that '[complex_value]' conform to 'RelationshipCollection' (requirement specified as 'Value' : 'RelationshipCollection')
Solution

To solve this, we followed Apple's advice and made our complex value abide to the Codable protocol.
"By default, SwiftData includes all noncomputed properties of a class as long as they use compatible types. The framework supports primitive types such as Bool, Int, and String, as well as complex value types such as structures, enumerations, and other value types that conform to the Codable protocol."
Looking to learn more about things you can do with SwiftData, Swift or XCode ?
Consult our quick start guide or search our blog to find educational content on learning how to use SwiftData, Swift or XCode.