|
The final challenge of cupcake corner is to move the order details to a struct and wrap the struct in a class.
However, we don't need to write custom encoding for the variables in the struct. This is because all of the data types (Bool, String, Double) inside the struct automatically conform to the conform to the codable protocol. My questions:
Encoding/decoding has been a challenging topic for me. I appreciate any guidance with this! |
|
@iospIT asks:
I think in another project you tap locations on a map of places you'd like to visit. These are processed as core locations in the struct, that is they are |
|
Please note: As a HWS+ member you get to see @twostraw's challenge solution.
|
|
To shed some light on your second question @iosPit, the static types array propery remains in the class so the code in the Picker view ForEach that loads the indices of the types array (in the ContentView file) does not change. If the static types property was moved to the struct, this code would need to change to point to the sturct type instead of the class type. The same goes for the code in CheckoutView that builds the confirmation message from the decoded return from the reqres.in site. It took me a minute to figure that one out after moving the static property in the struct and realizing the code would need to change!! |
|
You haven't actually wrapped your
Am I understanding the reasoning correctly? (Please correct me if I am not) Yes, that is the reason you do not need to provide custom codable conformance. Because they are all simple data types. What data types in structs would NOT conform to codable and would require a custom function to encode the data?
Any type of Why does Paul keep static let types = ["Vanilla", "Strawberry", "Chocolate", "Rainbow"] inside the class?
He likely leaves the array in the class because it isn't really necessary data that needs to be encoded and sent for the order to be processed. It is more of a user interface element that is used to display an understandable label to the user. When you create the struct to hold all of your data about an order, you would want to keep it as simple as possible to encode and send the smallest amount of data that is necessary to know everything that you need to know about an order. In this case, we already have an Why does Paul keep the CodingKeys enum inside the struct if we're not using them for a custom encoder?
I am not sure about this one, but I don't have access to Paul's finished solution for this project, so I'd have to look at how he did it to get a better idea. I know that you have to used coding keys when working with |
SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.
Sponsor Hacking with Swift and reach the world's largest Swift community!
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.
Link copied to your pasteboard.