03-09-2021, 02:51 PM
I thought I would check in and talk about some of my findings! So I started working with RestAPI trying to pull data from the TBDC Wordpress Site and WooCommerce. I have been fairly successful, thought I need to figure out how to get information from nested structures. With Swift, you are able to create what is called an observable object that you can use to parse JSON data and plug it into interface elements and user data. For example, the Structure "struc" I am using looks like this.
So a function will run pulling the JSON remotely, then use these Codable structures to store the data to use in the interface.
Doing so produces a result like this!
The next step is to figure out how to 1) get the data from the sub struc ProductImages then 2) start building a cart, payment system and have that all tie into Stripe and WooCommerce.
Code: (Select All)
struct Products: Codable {
var id: Int
var name: String
var status: String
var price: String
var images: [ProductImages]
}
struct ProductImages: Codable {
var id: Int
var src: String
}
So a function will run pulling the JSON remotely, then use these Codable structures to store the data to use in the interface.
Code: (Select All)
ForEach(productData, id: \.id) { product in
productCard(productName: product.name, productPrice: "$\(product.price)")
}
Doing so produces a result like this!
The next step is to figure out how to 1) get the data from the sub struc ProductImages then 2) start building a cart, payment system and have that all tie into Stripe and WooCommerce.