CKQueryOperation recordFetchBlock and queryCompletionBlock have been deprecated. How would I complete this operation now?
queryOperation.recordFetchedBlock = { record in
if let location = record["location1"] as? CLLocation {
var hideEvent: Bool = false
if let takeaway = record["host"] as? String {
for blockee in self.blockedFeed {
if takeaway == blockee {
hideEvent = true
}
}
for blocker in self.blockedFeeder {
if takeaway == blocker {
hideEvent = true
}
}
if hideEvent == false {
let identified = record.recordID.recordName
let category = record["type"] as? String ?? "defaultCategory"
let feature = """
{
"type": "Feature",
"properties": {
"category": "\(category)",
"recordID": "\(identified)"
},
"geometry": {
"type": "Point",
"coordinates": [\("\(location.coordinate.longitude)"), \("\(location.coordinate.latitude)")]
}
}
"""
features.append(feature)
}
}
}
}
// Completion block
queryOperation.queryCompletionBlock = { cursor, error in
if let error = error {
print("Error:", error)
return
}
if let cursor = cursor {
// Create a new operation with the cursor to get the next batch
let newOperation = CKQueryOperation(cursor: cursor)
newOperation.resultsLimit = CKQueryOperation.maximumResults
newOperation.recordFetchedBlock = queryOperation.recordFetchedBlock
newOperation.queryCompletionBlock = queryOperation.queryCompletionBlock
publicDB.add(newOperation)
} else {
let geoJSONString = """
{
"type": "FeatureCollection",
"features": [\(features.joined(separator: ","))]
}
"""
completion(geoJSONString.data(using: .utf8))
}
}
publicDB.add(queryOperation)
If you use code completion in Xcode, it shows you the replacement for
recordFetchedBlock. The replacement isrecordMatchedBlock.Xcode code completion also shows the replacement for
queryCompletionBlock(which was deprecated in iOS 15 apparently). The replacement isqueryResultBlock.The basic pattern for the two completion blocks is now: