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

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

Oscar de la Hera Gomez
Written by Oscar de la Hera Gomez
First published on 10/26/2023 at 16:55
Last Updated on 10/27/2023 at 12:01
<p>Three flowers that represent Swift, SwiftData and Xcode. Beneath them sits the text "Error No exact matches in call to instance method 'setValue'."</p>

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

SubscribeCheck out our SwiftData Quick Start Guide

Problem

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

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

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

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."

Apple: Preserving your app's model data across launches

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.

Consult our SwiftData Quick Start GuideSearch our Blog

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.
SubscribeContact UsVisit our BlogView our ServicesView our Work

Partner with us

We would love to get to know you and see how we can help your organization with its goals and needs.
Let's Talk

Stay Informed

Get occasional updates about our company, research, and product launches.
Subscribe