[英]CloudKit Query with modificationDate Always Returns No Results
My goal is to get User
records from CloudKit I specify in an array of CKRecord.ID
s, but only if they were updated more recently than my last updated date which I track locally.我的目标是从我在 CKRecord.ID 数组中指定的CKRecord.ID
获取User
记录,但前提是它们的更新时间比我在本地跟踪的上次更新日期更新。
I'm doing the following CloudKit query:我正在执行以下 CloudKit 查询:
var predicate:NSPredicate
if let lastChecked = defaults.object(forKey: "lastUserFetch") as? Date{
//Subsequent fetches
predicate = NSPredicate(format: "modificationDate > %@ AND recordID IN %@", argumentArray: [lastChecked, userRecordIDs])
}else{
//First fetch
predicate = NSPredicate(format: "recordID IN %@", argumentArray: [userRecordIDs])
}
let query = CKQuery(recordType: "User", predicate: predicate)
let operation = CKQueryOperation(query: query)
...
I initially set lastUserFetch
to nil
when my app launches, and the "First fetch" part of the query succeeds.当我的应用程序启动时,我最初将lastUserFetch
设置为nil
,并且查询的“首次获取”部分成功。 I get all the user records back.我取回了所有用户记录。
But once I set my lastUserFetch
date after the query is done:但是一旦我在查询完成后设置了lastUserFetch
日期:
defaults.set(Date(), forKey: "lastUserFetch")
I get 0
records returned when the modificationDate > %@
portion is included.当包含modificationDate > %@
部分时,我返回0
条记录。 I, of course, modify records in the CloudKit Dashboard, and I can see that their modificationDate
has updated and is newer than my lastUserFetch
date, but they still don't get returned in my search results.当然,我修改了 CloudKit 仪表板中的记录,我可以看到他们的modificationDate
已经更新并且比我的lastUserFetch
日期更新,但他们仍然没有在我的搜索结果中返回。
How do I combine a modificationDate
comparison with a recordID IN
query?如何将modificationDate
比较与recordID IN
查询相结合?
My goal is to get User
records from CloudKit I specify in an array of CKRecord.ID
s, but only if they were updated more recently than my last updated date which I track locally.我的目标是从我在 CKRecord.ID 数组中指定的CKRecord.ID
获取User
记录,但前提是它们的更新时间比我在本地跟踪的上次更新日期更晚。
I'm doing the following CloudKit query:我正在执行以下 CloudKit 查询:
var predicate:NSPredicate
if let lastChecked = defaults.object(forKey: "lastUserFetch") as? Date{
//Subsequent fetches
predicate = NSPredicate(format: "modificationDate > %@ AND recordID IN %@", argumentArray: [lastChecked, userRecordIDs])
}else{
//First fetch
predicate = NSPredicate(format: "recordID IN %@", argumentArray: [userRecordIDs])
}
let query = CKQuery(recordType: "User", predicate: predicate)
let operation = CKQueryOperation(query: query)
...
I initially set lastUserFetch
to nil
when my app launches, and the "First fetch" part of the query succeeds.当我的应用程序启动时,我最初将lastUserFetch
设置为nil
,并且查询的“First fetch”部分成功。 I get all the user records back.我取回所有用户记录。
But once I set my lastUserFetch
date after the query is done:但是一旦我在查询完成后设置了我的lastUserFetch
日期:
defaults.set(Date(), forKey: "lastUserFetch")
I get 0
records returned when the modificationDate > %@
portion is included.当包含modificationDate > %@
部分时,我得到0
条记录。 I, of course, modify records in the CloudKit Dashboard, and I can see that their modificationDate
has updated and is newer than my lastUserFetch
date, but they still don't get returned in my search results.当然,我修改了 CloudKit Dashboard 中的记录,我可以看到它们的modificationDate
已更新并且比我的lastUserFetch
日期更新,但它们仍然没有在我的搜索结果中返回。
How do I combine a modificationDate
comparison with a recordID IN
query?如何将modificationDate
比较与recordID IN
查询结合起来?
Make sure you have queryable index created on modificationDate field on cloudKit确保您在 cloudKit 上的 modificationDate 字段上创建了可查询索引
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.