Post

Replies

Boosts

Views

Activity

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")             }         }              }`
2
0
909
Oct ’22