Hi,
I've been using Core Data + CloudKit via NSPersistentCloudKitContainer for several years now. Back then I just created my Core Data AND CloudKit fields by hand.
Now the time has come for a little lightweight migration to a new Core Data model, let's say I just needed to add one String attribute.
So I've done the Core Data local migration as usual, then added this to container code:
try? persistentContainer.initializeCloudKitSchema(options: NSPersistentCloudKitContainerSchemaInitializationOptions())
Run. And everything worked great. but… Now I've noticed that CloudKit created new CKAsset fields for each String attribute that I had in Core Data (about 5 new CKAsset fields). Is this normal!? Why?
! Is it safe to deploy these changes to prod? ty.
ChatGPT said: "This field is used internally by CloudKit to handle large string values. If the string value is small enough, it is stored in the normal String field, but if it exceeds the size limit (about 1KB), the string is automatically stored as a CKAsset."
Adding a CKAsset
field for a Core Data String attribute is as designed. It is because the size of a CloudKit record (not counting assets) is limited to 1MB, while a Core Data attribute has no size limit.
What ChatGPT said is basically right – When the size of a Core Data String attribute exceeds a certain value, NSPersistentCloudKitContainer
converts it to a CKAsset
object in the data transformation process. Whether the value is about 1KB
or not is not formally documented though.
Best,
——
Ziqiao Chen
Worldwide Developer Relations.