0

Im trying fetch records from my private CloudKit DB.I could able to fetch the record.I stucked in accessing the fetched record

 func ReadRecord() {
     let predicate = NSPredicate(format: "name = %@", "samsung")
    let query = CKQuery(recordType: "MobileDetails", predicate: predicate)
    let operation = CKQueryOperation(query: query)
    print("Operation Result is \(operation)")
   var items: [Mobile] = []
    operation.recordMatchedBlock = { (recordID,record) in
                      switch record{
            case .success(let record):
                print("Success Case")
                items.append(Mobile(name: record["name"] as! String, price: record["price"]         as! String))
            case .failure(let error):
                print("Error Occured")
            }
                   
    }
   operation.queryResultBlock = { result in
        DispatchQueue.main.async{
          self.Array = items
       }
  }
    privateDatabase.add(operation)
    print("Array count is \(Array.count)")
    
    
}
This is my function to fetch a record
The recordmatchedBlock is not at all executing and I'm getting only the empty array in the queryResult block
Also tried the query CompletionBlock that too doesn't work
jnpdx
  • 45,847
  • 6
  • 64
  • 94
  • You should check for the error in queryResultblock. something like ;switch result { case let .success(cursor): print("the query was successful") case let .failure(error): print("Something went wrong") } You'll get an error in the failure case which should explain the issue. – john elemans Nov 06 '22 at 16:09

0 Answers0