How to solve "No exact matches in call to instance method 'setValue'"

Oscar de la Hera Gomez
Three flowers that represent Swift, SwiftData and Xcode. Beneath them sits the text "Error No exact matches in call to instance method 'setValue'."

Make sure that the SwiftData variable conforms to the Codable protocol.

Problem

A screenshot of Xcode showing how a build failed when adding a complex value to a SwiftData model.

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

A screenshot of Xcode showing how we made the complex value conform to the Codable protocol.

To solve this, we followed Apple's advice and made our complex value abide 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.

Any Questions?

We are actively looking for feedback on how to improve this resource. Please send us a note to inquiries@delasign.com with any thoughts or feedback you may have.
delasign logo

Book a Free Consultation.

An icon of an email.

Click here to email us.

Fill in the details below to book a free consultation or to let us know about something else. Whatever it is, we are here to help.

How can we help you ?

Contact Details