我无法访问CloudKit中我的记录类型的createdAt系统字段。我已经尝试将“ createdAt”和“ creationDate”作为CKQueryOperation.desiredKeys参数的参数。无论哪种方式,当我使用CKRecord.object(forKey :)访问createdAt字段时,都会得到nil。
这是我检索记录的代码:
$arr1 = array_column($arr1, 'dexcode');
$arr2 = array_column($arr2, 'dexcode');
print_r(array_diff($arr1, $arr2));
这是保存键的字符串变量的代码:
entries = [Entry]()
let predicate = NSPredicate(value: true)
let query = CKQuery(recordType: DatabaseNameStrings.recordTypeEntry, predicate: predicate)
let sortDescriptor = NSSortDescriptor(key: DatabaseNameStrings.recordFieldKeyCreationDate, ascending: true)
query.sortDescriptors = [sortDescriptor]
let queryOperation = CKQueryOperation(query: query)
queryOperation.desiredKeys = [DatabaseNameStrings.recordFieldKeyCreationDate, DatabaseNameStrings.fieldNameText]
queryOperation.recordFetchedBlock = {
(record: CKRecord) in
let entry = Entry(ckRecord: record)
self.entries.append(entry)
}
queryOperation.queryCompletionBlock = {
(cursor: CKQueryOperation.Cursor?, error: Error?) in
if let error = error {
print(error.localizedDescription)
} else {
DispatchQueue.main.async {
self.tableView.reloadData()
}
if let cursor = cursor {
let innerQueryOperation = CKQueryOperation(cursor: cursor)
innerQueryOperation.desiredKeys = queryOperation.desiredKeys
innerQueryOperation.recordFetchedBlock = queryOperation.recordFetchedBlock
innerQueryOperation.queryCompletionBlock = queryOperation.queryCompletionBlock
queryOperationQueue.addOperation(queryOperation)
}
}
}
queryOperationQueue.addOperation(queryOperation)
这是我访问createdAt字段的代码:
enum DatabaseNameStrings {
static let recordTypeEntry = "Entry"
static let fieldNameCreatedAt = "createdAt"
static let fieldNameText = "text"
static let recordFieldKeyCreationDate = "creationDate"
}
答案 0 :(得分:1)
我使用CKRecord.creationDate而不是CKRecord.object(forKey:)。