SwiftData, Core Data, and initializing CloudKit development Schema

I recently discovered the new documentation for enabling CloudKit sync with SwiftData. A key step I was missing in my previous setup was this step: Initialize the CloudKit development schema.

When I run this though, I get Core Data errors in my log...

CoreData: Unsupported attribute type

I've noticed that it seems to be preventing adding fields for my model properties that are Codable structs. I've been able to add Codable structs to my SwiftData models synced with CloudKit before. But using Core Data to initialize the CloudKit schema like the documentation suggests just doesn't work. Is there some other way around this? I'm about to just give up on CloudKit sync altogether. I need this to work because I'm trying to add some new fields and populate the fields with data based on existing data during the migration, but this seems to be preventing migration completely. If I don't initialize the schema, I get different errors and the ModelContainer won't initialize at all.

  • If instead I change the type to Data, it works fine. But then I need to manage another type that stores the raw data and manually decode and encode. This is a nightmare. Why does Apple release documentation that is completely non-functional for a very common use case?

Add a Comment

Replies

Silly question. Did you add 'import SwiftData' to the file?

  • Yes, both SwiftData and Core Data.

Add a Comment