01
Syncing Drink Data Across Views
Challenge: The app has three screens that all need the same drink data. Changes on one screen had to persist everywhere else without being changed.
Solution: Used @State as the main data point and passed data through views with @Binding. The Coffee struct holds all customization options, orderedCoffees array keeps track of the users ordered drinks.
Result: Adding a drink, confirming it in the sheet, and seeing it in the cart all works together as one shared array.
02
Pricing with Multiple Variables
Challenge: Each drink's price changes based on size, milk type, and whether it's iced. The cart has to show individual prices, upcharges, subtotal, and tax, and all of it needs to stay accurate as users add and remove drinks.
Solution:
Put the pricing logic inside the Coffee struct so each part of the price has its own function. The cart adds everything by looping through the array to get a subtotal and total.
Result: Prices calculate every time a drink is added or removed, so the subtotal, tax, and total in the cart always match what the user actually ordered.