UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

How to make a "add to cart" function in Swift ?

Forums > Swift

Hello. Im making a delivery food app . For each restaurant, i have different food. Im using firebase storage and firestore. When i click + buttom, i want to "add to cart" the items in the selected cell. A tutorial or how can i start it will help me. I really dont know where to start. Thanks!! This is my tableview https://imgur.com/Lft5Yzf

I'm retrieving data like this from firestore and firebase storage.

func getDatabaseRecords() {

            let db = Firestore.firestore()
           //  Empty the array
          food = []

        db.collection("RestaurantViewController").whereField("restaurantName", isEqualTo: restaurantName).getDocuments { (snapshot, error) in
                if let error = error {
                    print(error)
                    return
                } else {
                    for document in snapshot!.documents {
                        let data = document.data()
                        let newEntry = Food(photoKeyRestaurant: data["photoKeyRestaurant"] as! String, foodName: data["foodName"] as! String, foodDescription: data["foodDescription"] as! String, restaurantName: data["restaurantName"] as! String , priceFood: data["priceLabel"] as! Int
                        )

                        self.food.append(newEntry)
                    }
                }
                DispatchQueue.main.async {
                 //  self.datas = self.filteredData
                   self.tableView.reloadData()
                }
            }
        }

2      

TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!

Find out more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.