简体   繁体   English

CloudKit查询以供数组参考

[英]CloudKit query for reference in array

Let's say I have two CloudKit record types: 假设我有两种CloudKit记录类型:

  • Company 公司

    • name (string) 名称(字符串)
    • etc... 等等...
  • Employee 雇员

    • first name (string) 名(字符串)
    • etc... 等等...
    • company (reference to Company) 公司(参考公司)

In my app if I have an array Companies, is there a way to query CloudKit for all Employees whose company is in this array with a single query? 在我的应用程序中,如果我有公司数组,是否可以通过单个查询为公司在此数组中的所有雇员查询CloudKit? Obviously I could go through the companies array and query one by one, but if this array is large then that's going to be a lot slower. 显然,我可以遍历companies数组并逐个查询,但是如果这个数组很大,那将会慢很多。

The docs say that you can reference an array in a CKQuery predicate, but doesn't say how. 文档说您可以在CKQuery谓词中引用数组,但没有说明如何。

Yes you can use the predicate 是的,您可以使用谓词

NSPredicate(“%k IN %@“, company, arrayofcompaniesReference) NSPredicate(“%k IN%@”,公司,arrayofcompaniesReference)

  • company is the key in employee record type 公司是员工记录类型的关键
  • arrayOfCompaniesReference is the array of reference of companies you have. arrayOfCompaniesReference是您拥有的公司的参考数组。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM