Deleting data from cloudkit with swift

允我心安 提交于 2019-12-04 13:29:24

问题


How do I delete some data I put into the cloud? I made an app that when you enter a url in 1 view controller it uploads into the cloud, and when you go to another view controller it shows the url you entered before from the cloud in a webview. for example, when you enter www.hello.com, it goes into the cloud, and when you go to the webview on a different view controller it loads www.hello.com.

My problem:

When I enter a second url, it still loads the first one. How do I get it to load the latest one I uploaded? Is there a way to delete the first one when the second one is uploaded?


回答1:


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.



来源:https://stackoverflow.com/questions/28681393/deleting-data-from-cloudkit-with-swift

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