-->

How to modify CloudKit Reference Lists

2019-04-15 22:34发布

问题:

I can modify the Reference List attribute of my CKRecord in the dashboard without problems, but how can I modify it programmatically?

I currently try modifying it as a NSArray. It does not give me any sort of error but even though the array content is fine, the attribute does not get set.

Also the documentation on reference lists is either well-hidden or non-existent.

                CKReference *reference = [[CKReference alloc] initWithRecord:connectionRecord action:CKReferenceActionNone];
                NSMutableArray *list_a = [record_a[@"connections"] mutableCopy];
                if (!list_a) list_a = [NSMutableArray array];
                [list_a addObject:reference];
                record_a[@"connections"] = list_a;

                [publicDatabase saveRecord:record_a completionHandler:^(CKRecord *artworkRecord, NSError *error){
                    if (!error) {
                        // Insert successfully saved record code
                    }
                    else {
                        // Insert error handling
                    }
                }];

I am thankful for any ideas or suggestions.

回答1:

Turns out that one has to use CKModifyRecordsOperation to modify existing CKRecords.