Possible convert [CKRecord] to [CKRecord.ID : Int]?

I have an error Cannot assign value of type '[CKRecord]' to type '[CKRecord.ID : Int]'. Is it possible to convert [CKRecord] to [CKRecord.ID : Int]?

Answered by matovsky in 698807022

Closed

Could you show the code where the error occurs ?

Where are you using '[CKRecord]'

@Published var checkedInProfiles: [CKRecord.ID: Int] = [:] ... func getCheckedInCounts() {         ckController.database.fetchCheckedInProfilesCount(with: RecordType.profile) { (results, moreComing, error) in             DispatchQueue.main.async { [self] in                 checkedInProfiles = results             }         }   }

Thanks for the code. Comments are messing code presentation, it is better to post in a new reply:

@Published var checkedInProfiles: [CKRecord.ID: Int] = [:]

func getCheckedInCounts() {
    ckController.database.fetchCheckedInProfilesCount(with: RecordType.profile) { (results, moreComing, error) in
        DispatchQueue.main.async { [self] in
            checkedInProfiles = results
        }
    }
    
}

So I assume you get the error in

            checkedInProfiles = results

Most likely, results in fetchCheckedInProfilesCount is a [CKRecord], hence a mismatch.

Could you confirm by showing fetchCheckedInProfilesCount func ?

Thank you very much! I got another problem: Cast from '[AnyObject]' to unrelated type '[CKRecord.ID : Int]' always fails Here:

operation.queryCompletionBlock = { (cursor, error) in
       let moreComing = (cursor == nil) ? false : true
       completionHandler(results as [AnyObject] as! [CKRecord.ID: Int], moreComing, error as NSError?)
       if let cursor = cursor {
           self.continueCheckedInProfilesCount(with: cursor, results: results, completionHandler: completionHandler)
     }
 }
Accepted Answer

Closed

Possible convert [CKRecord] to [CKRecord.ID : Int]?
 
 
Q