0

I have [String] and [Int] attributes in my entity on Core Data/type on CloudKit, where they are String list and Int64 list respectively. I'm trying to synchronize them via NSPersistentCloudKitContainer (public server). All other attributes synchronize properly, but these two do not at all. The other ones are simple - String, Date, Int64/Int. I want to make them sync, too.

Both of them are Transformable, with their respective Custom class set to [String] and [Int]. The codegen is Manual/None, so I can create unwrapped attributes for a later use.

When I run the app at first launch I get the CKRecord with their data, too - I mean I see in the debug their values in the downloaded records information. However, when I check Core Data, it tells me nil.

I've tried setting both NSSecureUnarchiveFromData and NSSecureUnarchiveFromDataTransformerName, it didn't work out.

It's clear to me that the arrays' data is downloaded, I don't understand why Core Data doesn't like the arrays.

1 Answers1

0

Okay, managed to solve it:

  1. It must not be a List of any sort on CloudKit, but Bytes.

  2. The rest is simply converting the arrays into NSData when uploading. I did it with Data

    let archivedString = try? NSKeyedArchiver.archivedData(withRootObject: [String], requiringSecureCoding: true)

Same goes for [Int].

  • Could you elaborate on how you solved this? I am in a similar situation. My Core Data entity has an attribute of type [String] (transformable) and it is being saved in CloudKit as type Bytes. When I make a fetch request for the CKRecord and try to extract the [String] from the Bytes, it throws an error: strings = record["CD_strings"] as! [String] How are you supposed to get the CKRecordValue as type [String]? – PointOfNilReturn Jun 01 '21 at 23:10
  • 1
    I think you should not case it yet as [String] when fetching, but as Data and then try to unarchive it. – Атанас Начков Jun 02 '21 at 10:46