You can delete entries with the code as follows:
database.deleteRecordWithID(CKRecordID(recordName: recordId), completionHandler: {recordID, error in
NSLog("OK or \(error)")
}
where the database is the CKDatabase that you are using.
But in your situation, it would be better to update the previous record created. Another solution would be to query your data when using the sort order for createDate as follows:
query.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: false)]
Then just select the first one, since the last one you saved. A good addition is that you will have a history in your database.
source
share