Deleting data from cloudkit with swift

别来无恙 提交于 2019-12-03 08:23:59

You can delete records with code like this:

database.deleteRecordWithID(CKRecordID(recordName: recordId), completionHandler: {recordID, error in 
 NSLog("OK or \(error)")
}

where database is the CKDatabase that you are using.

But in your situation it might be better to update the previous created record. An other solution would be to query your data while using a sort order on the creationDate like this:

query.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: false)]

Then just pick the first one since that's the last one you saved. A nice extra is that you would have a history in your database.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!