How to query by creationDate in CloudKit?

前端 未结 1 1352
情歌与酒
情歌与酒 2020-12-31 07:38

I want to fetch the last X minutes of public/private entries from CloudKit.

I tried something in this effect but failed:

    let date = NSDate(timeIn         


        
相关标签:
1条回答
  • 2020-12-31 08:05

    UPDATE 10/5/2020:

    Found out my own question. You'll need to log in to CloudKit dashboard, go to Schema and make sure "Index Type" is set to queryable.

    Here's more detailed document of what kind of NSPredicate you can use for CloudKit: https://developer.apple.com/documentation/cloudkit/ckquery#//apple_ref/doc/uid/TP40014043-CH1-SW8

    Once setup, you'll be able to query by date like so:

    let date = NSDate(timeInterval: -60.0 * 120, sinceDate: NSDate())
    let predicate = NSPredicate(format: "creationDate > %@", date)
    

    [DEPRECATED] Screenshot of CloudKit dashboard for first accepted answer below:

    enter image description here

    0 讨论(0)
提交回复
热议问题