Save multiple CKRecords at one time with CloudKit and Swift

Is it possible to save multiple objects CKRecordin one operation CloudKitusing Swift? I know how to extract multiple records at once, using things like CKFetchRecordsOperationor even regular performQuery. I just realized that I’m not sure that you can save several new records in one operation. The way I do it still seems ineffective to me. For instance:

let recordsToSave:[CKRecord]!

for newRecord in recordsToSave {

    if let database = self.publicDatabase {

        database.saveRecord(newRecord, completionHandler: { (record:CKRecord?, error:NSError?) in

            // Check if there was an error
            if error != nil {

                // There was an error, handle it properly.

            }
            else {

                // There wasn't an error
                if let savedRecord = record {

                    // Handle saved record accordingly.

                }

            }
        })
}

And while it works fine and dandy, it seems to me that it is extremely inefficient. I would think that it makes sense to have a specific function to call the entire array CKRecords, instead of having to call the database every time through a loop. Essentially, this is what I can hope for . I can do:

let recordsToSave:[CKRecord]!

if let database = self.publicDatabase {

    // SOMETHING HERE LIKE database.saveRECORDS (plural) ????
    database.saveRecords(recordsToSave, completionHandler: { (records:[CKRecord]?, error:NSError?) in

        // Check if there was an error
        if error != nil {

            // There was an error, handle it properly.

        }
        else {

                // There wasn't an error
                if let savedRecords = records {


                }

            }
        })
}

, . , database.saveRecords ( ). - ? , , , , - .

, , .

- CKRecords , CloudKit? . !

+4
1

saveRecord . CKDatabase .

// , CKModifyRecordsOperation. /, . , saveRecord.

CloudKit Framework, .

+7

All Articles