我正在尝试从云工具包下载多个项目,但出现错误“无法分配类型值(CKQueryCursor !, NSError)->()键入(CKQueryCursor ?, NSError?)-> void”

let locationToLookFor = CLLocation()
let predicate = NSPredicate(format: "location = %@", locationToLookFor as CLLocation)
let query = CKQuery(recordType: "Location", predicate: predicate)
let operation = CKQueryOperation(query: query)
operation.recordFetchedBlock = self.recordFetchBlock
operation.queryCompletionBlock =
{
    [weak self]
    (cursor: CKQueryCursor!, error: NSError) in
    if(cursor != nil)
    {
        print("Fetching records")
        let newOperation = CKQueryOperation(cursor: cursor)
        operation.recordFetchedBlock = recordFetchBlock
        operation.queryCompletionBlock = operation.queryCompletionBlock
        self!.operationQueue.addOperation(newOperation)
    }
    else {
        print("We have fetched all data")
    }
}
operationQueue.addOperation(operation)

最佳答案

您的关闭签名与所需签名不匹配。如错误消息中所示,cursorerror应该是可选的。您还会收到一个错误,因为在将cursor提供给新操作时未将其解包。

尝试:

operation.queryCompletionBlock =
{
    [weak self]
    (cursor: CKQueryCursor?, error: NSError?) -> Void in
    if let cursor = cursor
    {
        print("Fetching records")
        let newOperation = CKQueryOperation(cursor: cursor)
        operation.recordFetchedBlock = recordFetchBlock
        operation.queryCompletionBlock = operation.queryCompletionBlock
        self?.operationQueue.addOperation(newOperation)
    }
    else {
        print("We have fetched all data")
    }
}

关于ios - 如何从Cloudkit下载多个记录,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38687783/

10-10 07:17