2016-06-27 74 views
0

對不起有一個愚蠢的簡單問題。我想列出所有創建時間超過24小時的記錄。儀表板上設置了創建日期的查詢字段。我有這個代碼......但我似乎無法解決這個問題。抓取iCloudKit記錄超過24小時

我得到這個代碼...

let container = CKContainer(identifier: "iCloud.blah") 
    let publicDB = container.publicCloudDatabase 
// 24 hours ago 
    let date = NSDate(timeInterval: -60.0 * 1440, sinceDate: NSDate()) 
    let predicate = NSPredicate(format: "creationDate < %@", date) 
    let query = CKQuery(recordType: "Collection", predicate: predicate) 

但是,這讓我已經在過去24小時內已創建的所有記錄;我不想要他們,我想要所有超過24小時的記錄。我的記錄只包含一個字段,而且這是一項資產。開始以爲是我的部分問題...

enter image description here

如果部署不看好它的索引大小? 0字節?

回答

0

好吧,我想我找到了我的問題的答案。這個代碼很好,我的錯誤是在選擇記錄時只選擇recordID。我也需要選擇元數據。

readerOperation = CKQueryOperation(query:query) readerOperation.desiredKeys = [「record.recordID.recordName」,「record.creationDate」];

readerOperation.recordFetchedBlock = { (record) in 
     self.records2Erase.append(record.recordID) 
    } 
    readerOperation.queryCompletionBlock = {(cursor, error) in 
      if error != nil { 
       dispatch_async(dispatch_get_main_queue()) { 
        self.showAlert(message: error!.localizedDescription) 
       } 
      } else {     
       print("records2Erase since \(date) \(self.records2Erase)") 
      } 


    }