|
I was trying to adapt the example from day 49 to work with the data from Day 60. The code below did not work and I am stumped as to why it failed. This is just a quick ContentView to test it. I peaked ahead to the HWS+ solution for this and loadData() works. He defined the Decoder first I think so he could set the Date conversion... but short of that, why does the code below not work? It just displays nothing when I run it:
|
|
Hi! Just modify your
|
|
So was it failing due to the lack of the date code? I was not even displaying date, so I didnt put it in there. Also, the Day 49 code does not create the decoder first... so I am guessing you have to in order for it to work due to the date? |
|
Yes, you're not displaying the date, however your struct Result contains that property. Once you get the data from the server, decoder still tries to decode but cannot decode that property. As for decoder instantiating before, you need to access .dateDecodingStrategy so that's why you can create it prior, set it up and then use that ready-to-use decoder later in the code. |
|
There are actually two mismatches. Try to use this code to see the error prints.
You'll see this error printed to console:
Once you change it to:
This tells that you cannot decode Date
Using Hope this is more clear now. |
|
ooops I didnt see your comment, I see what is going on... Result vs Response.... one of my bad habits of getting confused on name. This helped immensely @ygeras. Thank you so much! |
|
This is but one example of why it's best to use more descriptive names than (Not to mention that Swift has a built-in |
|
@roosterboy, I might be wrong, but I think Paul used Result in the one example as that is what the Itunes JSON returned... an array starting with [Result @ygeras, thank you, I am going to study what you typed above! Thank you to both of you :D |
|
Granite4Less has been proudly serving Montreal and surrounding areas for years, with over 25 years of combined experience. Granite 4 less is a family company focused on quality and know-how. |
SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure and A/B test your entire paywall UI 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.