[英]Difference between CKQueryOperation and Perform(Fetch…)
I'm new to working with CloudKit and database fetching and I've looked at the CKDataBaseOperation calls, so I'm trying to understand the real differences between adding an operation to a database and using "normal" function calls on that database if they both produce, more or less, the same results. 我刚开始使用CloudKit和数据库获取,我查看了CKDataBaseOperation调用,所以我试图理解在数据库中添加操作和在数据库上使用“普通”函数调用之间的真正区别两者都产生或多或少相同的结果。
Why would adding an operation be more desirable over a function call and in what situations? 为什么在函数调用和什么情况下添加操作更合适?
Thanks for helping me understand this. 谢谢你帮我理解这一点。 I'm trying to learn as much as I can about Swift. 我正在努力学习关于斯威夫特的事情。
In CloudKit
most of the tasks have 2 ways of doing things: 在CloudKit
大多数任务都有两种处理方式:
CKDatabase.fetch
, you would need to specify the record IDs that you want to fetch. 如果使用CKDatabase.fetch
,则需要指定要获取的记录ID。 CKQueryOperation
, you can query based on field values. 如果使用CKQueryOperation
,则可以基于字段值进行查询。 CKDatabase.save
, you can save 1 record with every function call. 如果使用CKDatabase.save
,则可以在每次函数调用时保存1条记录。 Each function call would result in a separate server request. 每个函数调用都会产生一个单独的服务器请求。 If you want to save 200 records, you would have to run it in a loop and would make 200 server requests which is not very efficient. 如果要保存200条记录,则必须在循环中运行它,并且会产生200个服务器请求,这些请求效率不高。 CloudKit also has a limit on the number of server requests you can make per second. CloudKit还限制了您每秒可以进行的服务器请求数。 This way you would exhaust your quota very quickly. 这样你就可以很快耗尽你的配额。 CKModifyRecordsOperation
, you can save 200 records all at once*, by passing it as an array. 如果使用CKModifyRecordsOperation
,则可以一次性保存200条记录*,方法是将其作为数组传递。 So you would be making far lesser server requests. 所以你会做出更少的服务器请求。 *Note: The server imposes a limit on the number of records it can save in 1 request but it is definitely better than creating a separate request to save each record. *注意:服务器对可以在1个请求中保存的记录数量施加限制,但它肯定比创建保存每个记录的单独请求更好。
Operation
(earlier used to be referred as NSOperation
) 可能有助于学习和观看有关Operation
WWDC视频(之前曾被称为NSOperation
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.