0

I'm using following code to fetch my CloudKit data:

func getShoppingList(completionHandler: @escaping ([ShoppingListEntry]?, Error?) -> ()) {

    var shoppingListEntrys: [ShoppingListEntry] = []

    let container = CKContainer.default()
    let publicDB = container.publicCloudDatabase
    let predicate = NSPredicate(value: true)
    let query = CKQuery(recordType: "ShoppingListEntry", predicate: predicate)

    publicDB.perform(query, inZoneWith: nil) { (results, error) -> Void in
        if error != nil {
            print(error!)
            completionHandler(nil, error)
        }
        else {

            for var value in results! {

                let entry: ShoppingListEntry = ShoppingListEntry()

                entry.amount = value.value(forKey: "amound") as! Int
                entry.description = value.value(forKey: "description") as! String
                entry.isSelected = value.value(forKey: "isSelected") as! Bool

                shoppingListEntrys.append(entry)
            }
        }
    }

    index = shoppingListEntrys.count + 1
    completionHandler(shoppingListEntrys, nil)
}

I call this function with this code:

cloudKit.getShoppingList() { entrys, error in

        self.shoppingListEntrys = entrys!
        self.tableViewShoppingList.reloadData()
    }

My problem is, that the returned shoppingList Array is empty...

Philipp Rosengart
  • 713
  • 1
  • 8
  • 20

0 Answers0