Creating the shopping cart
Now, that the products side is complete, let's look at what we need to do for the cart view. We have a couple of things to do for our shopping cart. Let's take a look before we dig in:
We need to update our cart so that we can take products and also see the total value of the transaction. First, we will create the cart item, and then we will work on the cart content after that. Let's get started.
Designing the cart item view
We are going to work on the cart item view as we will need this in the next step. Create a new SwiftUI file named CartItemView
and save it to the Cart
folder, which is inside the Supporting Views
folder. Update previews to the following:
CartItemView() .previewLayout(.fixed(width: 375, height: 100))
Next, replace Text(“Hello, world!”)
with the following HStack
:
HStack { &...