Instance Method

save(_:completionHandler:)

Saves one record zone asynchronously, with a low priority, to the current database.

Declaration

func save(_ zone: CKRecordZone, completionHandler: @escaping (CKRecordZone?, Error?) -> Void)

Parameters

zone

The zone you want to save to the database. This method throws an exception if this parameter is nil.

completionHandler

The block to execute with the results. Your block must be capable of running on any thread of the app and must take the following parameters:

zone

The CKRecordZone object you attempted to save.

error

An error object, or nil if the record zone was saved successfully. Use the information in the error object to determine whether a problem has a workaround.

Discussion

Use this method to save a record zone to the database so that you can subsequently store records in it. Record zones must be saved before you attempt to save any records that reside in that zone. Because this method executes asynchronously, use the completion handler to verify that the zone was saved successfully before attempting to save any records.

This method saves the record zone with a low priority, which may cause the task to execute after higher-priority tasks. To save the record zone more urgently, create a CKModifyRecordZonesOperation object with the priority you want. You can also use that operation object to save multiple record zones all at once.

See Also

Accessing Record Zones

func fetchAllRecordZones(completionHandler: ([CKRecordZone]?, Error?) -> Void)

Fetches all record zones asynchronously, with a low priority, from the current database.

func fetch(withRecordZoneID: CKRecordZone.ID, completionHandler: (CKRecordZone?, Error?) -> Void)

Fetches one record zone asynchronously, with a low priority, from the current database.

func delete(withRecordZoneID: CKRecordZone.ID, completionHandler: (CKRecordZone.ID?, Error?) -> Void)

Deletes one record zone (and its contents) asynchronously, with a low priority, from the current database.