2016-07-09 263 views
0

我無法讓我的應用程序獲取所有類型的記錄並將每個用戶記錄放入數組中。如何從cloudkit獲取所有記錄

這是保存記錄

func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { 
    let id = CKRecordID(recordName: "01") 
    let locationRecord = CKRecord(recordType: "location", recordID: id) 
    locationRecord.setObject(location, forKey: "location") 
    let publicData = CKContainer.defaultContainer().publicCloudDatabase 
    publicData.saveRecord(locationRecord) { record, error in 
    //.. 
    } 
} 

回答

3

你需要使用CKQueryNSPredicate設置爲true代碼:

let predicate = NSPredicate(value: true) 

let query = CKQuery(recordType: "location", predicate: predicate) 

database?.performQuery(query, inZoneWithID: nil) { results, error in 
    //... 
} 
+0

根據CKQuery API參考:「謂詞基於格式字符串,不能使用基於值或基於塊的謂詞。「我不認爲它總是這樣,但目前這個答案不起作用。 –

-1
CKDatabase *publicDatabase = [[CKContainer defaultContainer]]; 

NSPredicate *predicate = [NSPredicate predicateWithValue:YES]; 

CKQuery *query = [[CKQuery alloc] initWithRecordType:@"Group_attributes"]; 

[publicDatabase performQuery:query inZoneWithID:nil:^(NSArray *results,error){ 

}]; 
+0

根據CKQuery API參考:「謂詞基於格式字符串,不能使用基於值或基於塊的謂詞。」我不認爲它總是這樣,但目前這個答案不起作用。 –