Fetch Results from Reference (List)

Hey All, I have a Reference (List) property in my CloudKit record type that points to a variety of locations. When I fetch the record with the reference (List), how do I then fetch the locations that the reference (List) is pointing to? Thanks! Here is my `code:    func getLocationsWhereVendorIsSelling() {

        

        // Retrieve Profile Record ID

        guard let profileRecordID = CloudKitManager.shared.profileRecordID else { return }

        

        CloudKitManager.shared.fetchRecord(with: profileRecordID) { result in

            switch result {

        // Get profile record

            case .success(let record):

                // Location References in profile

                let locationReferences = record[MLProfile.kIsSellingAt] as? [CKRecord.Reference]

                

                // Get all locations

                let locations = self.locationManager.locations

                

                // Filter locations by the ones that have the reference

                let predicate = NSPredicate(format: "%K CONTAINS %@", locationReferences!, locations)

                

                // Add locations to the soldToLocations array

                let query = CKQuery(recordType: RecordType.location, predicate: predicate)

                CKContainer.default().publicCloudDatabase.perform(query, inZoneWith: nil) {

                    locationRecords, error in

                    guard let locationRecords = locationRecords, error == nil else {

                        print(error!.localizedDescription)

                            return

                        }

                    

                print(locationRecords)

                    

                }

                

            case .failure(_):

                print("Error getting all the locations")

            }

        }

        

    }`

The CKRecord.Reference class has a recordID (CKRecord.ID) property, which you can use to fetch the actual referenced CKRecord. In your case it looks like you'd be fetching a list, so you could use the fetch(withRecordIDs:) method to fetch all IDs in a single transaction documented here.

Thanks for the response! How do I access the recordIDs? My constant "let locationReferences..." does not have a recordID that I am able to access. I thought about using a for loop to loop through the locationReferences, but that does not seem like the right approach.

Fetch Results from Reference (List)
 
 
Q