我正在尝试使用CloudKit和光标从我的iCloud公共数据库下载一批记录.无论resultLimit如何设置,代码都可以在前3次执行中正常工作,但是从不执行第4个完成块.如果没有设置resultsLimit我得到300条记录,如果它设置为50我得到150,如果它设置为5我得到15 ...
没有报告错误,该块似乎已添加,但从未执行过.平台是OS X.以下是有问题的代码:
let queryOp = CKQueryOperation(query: query)
queryOp.recordFetchedBlock = self.fetchedDetailRecord
queryOp.resultsLimit = 5
queryOp.queryCompletionBlock = { [weak self]
(cursor: CKQueryCursor!, error: NSError!) -> Void in
println("comp block called with \(cursor) \(error)")
if error != nil {
println("Error on fetch \(error.userInfo)")
} else {
if cursor != nil {
let nextOp = CKQueryOperation(cursor: cursor)
nextOp.recordFetchedBlock = self!.fetchedDetailRecord
nextOp.queryCompletionBlock = queryOp.queryCompletionBlock
nextOp.resultsLimit = 5
self!.publicDatabase?.addOperation(nextOp)
println("added next fetch")
} else {
self!.fileHandle!.closeFile()
self!.exportProgressIndicator.stopAnimation(self)
}
}
}
self.publicDatabase?.addOperation(queryOp)
Run Code Online (Sandbox Code Playgroud)
这是控制台的结果 -
459013587628.012 …