After a while, you'll reach the limits of the convenience API. Thankfully, you can use operations instead which provides a lot of power and flexibility.
How can you set the recordID from code instead of having it set automatically?
I have searched for a way to do this in Swift, but I have not found a solution that works for me. Any help would be greatly appreciated mu CloudKit database is getting full of duplicate records that are not necessary. If I could set the recordID to a unique name appropriate for my application such as “todaysTempEloy” then the record would be replaced when I update the temperature for today in Eloy with the recordID “todaysTempEloy”.
I’m not sure if what you are asking is possible. That said, have you thought about querying the data store before you write to it? That is, see if the record exists and if so, update it vs. just writing out to the database each time?
I could not figure out how to get this to work. Is there an example somewhere?
The ID of a new record is always set at initialization time. If you use the init(__recordType:recordID:) method to initialize the record, the ID is derived from the CKRecord.ID object you provide. In all other cases, the record generates a UUID and bases its ID on that value. The ID of a record never changes over the lifetime of that record.
When you save a new record object to the server, the server validates the uniqueness of the record but reports an error only if the save policy calls for it. Specifically, it reports an error when the save policy is set to CKModifyRecordsOperation.RecordSavePolicy.ifServerRecordUnchanged, which is the default. For other save policies, the server overwrites the contents of the existing record accordingly.