我正在尝试从云端套件下载多个项目,但我收到错误“无法分配类型值(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)
答案 0 :(得分:2)
您的封闭签名与所需签名不符。如错误消息所示,cursor
应该是可选的error
。您还会收到错误,因为在将其提供给新操作时,您不会解包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")
}
}