Saving FamilyActivitySelection with Swift Data

I have a model with a FamilyActivitySelection, currently i'm using a codable struct to store it with UserDefaults, but would prefer strongly to transition to Swift Data

Do you have a question you want to ask?

Oh haha sorry, I was wondering if it’s possible, and how one could? As far as I can tell the FamilyActivitySelection is not a data type that can be stored, and it’s not possible to recreate the object from any primitive representation of its attributes? Docs don’t seem to have much info on this.

FamilyActivitySelection is Codable and so SwiftData should be able to handle and you should be able to use the type in a SwiftData model directly.

As far as I know, using Codable types in SwiftData has some corner cases that need attentions. I don't have more details to share here, but if you see anything not working, feel free to follow up here.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

Saving FamilyActivitySelection with Swift Data
 
 
Q