快速从CloudKit删除数据 [英] Deleting data from cloudkit with swift

查看:83
本文介绍了快速从CloudKit删除数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何删除一些放入云中的数据?我制作了一个应用程序,当您在1个视图控制器中输入URL时,它会上传到云中;当您转到另一个视图控制器时,它将显示您从Web视图中的云中输入的URL。例如,当您输入www.hello.com时,它将进入云端,而当您使用其他视图控制器的webview时,它将加载www.hello.com。

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.

我的问题:

当我输入第二个URL时,它仍然会加载第一个。如何加载我上传的最新影片?

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?

推荐答案

您可以使用以下代码删除记录:

You can delete records with code like this:

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

其中数据库是您所使用的CKDatabase

where database is the CKDatabase that you are using.

但是在您的情况下,更新以前创建的记录可能会更好。另一种解决方案是在creationDate上使用排序顺序时查询数据这个:

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.

这篇关于快速从CloudKit删除数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆