|
I am a complete SwiftUI beginner. I have gone through Apple's Landmarks tutorial, and a bunch of the videos here. I am now trying to render out a view with some alternative JSON as the data. However, when I try and use that data I get a The logs don't show me anything I understand, they don't even reference that same message so I am lost. I thought it must be something to do with how I have mapped the data. Here is my mapping of the JSON called Competition.swift, followed by the JSON, followed by my simple view. Hope somebody can shed some light on what I have wrong here?
And here is the JSON file:
And here is the view that won't load/preview:
|
|
Don't throw a FatalError when decoding but catch the error. Here you find an example how to catch the error when decoding a json. This gives you a hint where to look. |
|
SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until February 9th. Sponsor Hacking with Swift and reach the world's largest Swift community! |
|
@NigelGee sadly that made no difference. Will likely just strip my model and data right back and try adding them in one by one. @Hatsushira - I've added a Here is the modelData:
|
|
You want to know exactly as possible where the error is:
|
|
Hi
Then added this model
Then created this in
Showed in preview English Premier League So worked fine
You may have trouble with
So now can do this
|
|
@NigelGee thanks very much for looking at that. I was absolutely clueless at this point! Looks like one of the main things I got wrong is not following the nesting structure of the JSON in the structs. I somehow got it in my head that the nested structs could be defined flatter. |
|
If you use some thing like Ducky you can choose your model (sometime might have to amend but it get you most of the way). Stewart Lynch does a YouTube Video Ducky Model Editor for Swift Developers |
|
Sorry for the basic questions @NigelGee; Using your second model, and the second version of body, I get an error |
|
SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until February 9th.
Sponsor Hacking with Swift and reach the world's largest Swift community!
You need to create an account or log in to reply.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.