Experienced devs may note that I did not use @MainActor in the ViewModel. This was on purpose. I will be showing the “purple error” in the next lesson when we run in the simulator and will show how MainActor fixes this.
I could have declared them outside the class, but since the JSON structs aren't going to be used by any other file other than this one, it makes sense to keep them inside this class. The first one should be "private" so it doesn't show up in code completion when I access the ViewModel from outside this file. They're only used for parsing the JSON results that I get back in the data value that's returned from decoding JSON. You could certainly have pulled them out of the class & even put them in a separate file, but it's better practice to keep them hidden inside the only file where they're going to be used if they're only used for JSON parsing. The second you use one of these structs in a View, then you'd want to pull it out of the class & it'd be best to put in a separate file, too, so it would be easy to see in the Project Manager if you're looking to see where that struct is set up.
Hie, You video help me a lot but I am stuck with one issue , when i hit the API then I get this error "Json Error: Could not decode returned data". Thank you
You get this when the json you are trying to decide doesn’t match the values you ads Regino to decode info. You might go back and try to add one property at a time until you see the problem. Make sure properties have the same name and spelling as keys in json.
Thanks prof for the great lesson. @27.09 regarding the "Hashable" error, I noticed this problem can be fixed if we specify id:\.self.name rather than id:\.self . I suspect this is due to id:\.self is trying to use the array as unique ID thus requiring to conform to Hashable vs using just the String property .name as unique ID which does not require Hashable protocol
You have explained this vividly and simple. thanks I finally understood.
Thanks, friend. Keep hacking and tell others. Cheers!
thanks for your videos. Best regards from Moscow.
Спасибо друг.
Hi John, excellent explanation on API Call with JSON parsing ! Thank you very much for sharing !
Glad you’ve enjoyed it. Keep hacking!
This video has been helpful. Thank you.
Thank you very much , your explanation is very cool 🙂
Glad you liked it!
Experienced devs may note that I did not use @MainActor in the ViewModel. This was on purpose. I will be showing the “purple error” in the next lesson when we run in the simulator and will show how MainActor fixes this.
🎉❤ Thank you !!!!!
Glad you like it!
Excellent explanation… just question. Why you declared structs inside class?
I could have declared them outside the class, but since the JSON structs aren't going to be used by any other file other than this one, it makes sense to keep them inside this class. The first one should be "private" so it doesn't show up in code completion when I access the ViewModel from outside this file. They're only used for parsing the JSON results that I get back in the data value that's returned from decoding JSON. You could certainly have pulled them out of the class & even put them in a separate file, but it's better practice to keep them hidden inside the only file where they're going to be used if they're only used for JSON parsing. The second you use one of these structs in a View, then you'd want to pull it out of the class & it'd be best to put in a separate file, too, so it would be easy to see in the Project Manager if you're looking to see where that struct is set up.
@@profgallaugher thank you
Hie, You video help me a lot but I am stuck with one issue , when i hit the API then I get this error "Json Error: Could not decode returned data". Thank you
You get this when the json you are trying to decide doesn’t match the values you ads Regino to decode info. You might go back and try to add one property at a time until you see the problem. Make sure properties have the same name and spelling as keys in json.
Thanks prof for the great lesson.
@27.09 regarding the "Hashable" error, I noticed this problem can be fixed if we specify id:\.self.name rather than id:\.self . I suspect this is due to id:\.self is trying to use the array as unique ID thus requiring to conform to Hashable vs using just the String property .name as unique ID which does not require Hashable protocol
Thanks! It’s so great hearing from students who have figured out a new method. Really appreciate the tip. Cheers!