我有CKQueryOperation
一千条记录,因此我需要多次执行该操作。我尝试更改光标并添加如下代码中的操作:
let queryOperation = CKQueryOperation(query: query)
queryOperation.recordFetchedBlock = { (rule: CKRecord) in
print(rule)
}
queryOperation.database = publicDB
queryOperation.queryCompletionBlock = { (cursor : CKQueryCursor?, error : NSError?) in
if error != nil {
print(error?.localizedFailureReason)
} else {
if cursor != nil { // The cursor is not nil thus we still have some records to download
queryOperation.cursor = cursor
queue.addOperation(queryOperation)
} else {
print("Done")
}
}
}
// Creation of the dependent operation secondQueryOperation
queue.addOperations([queryOperation, secondQueryOperation], waitUntilFinished: true)
运行时它崩溃并返回[NSOperationQueue addOperation:]: operation is executing and cannot be enqueued
。我能做什么?之后我还有其他操作依赖于这个 queryOperation 所以我需要在启动其他之前正确命中CKOperation
。