|
Hi, I am trying to get data from JSON. So far, I can extract it and print it. My goal now is to be able to use it in my ContentView so that it can be used in a Text View or something similar. I have tried creating @State variables, passing it as a parameter, etc. etc. and nothing seems to work. I'm fairly new to SwiftUI, so I appreciate the help!
|
|
@twoStraws cautions us to criticize ideas, not people. So I will try to be careful with my response. This site, HackingWithSwift, is a community where we try to help others on their path to becoming iOS developers. We follow and support a 100 Day program that @twoStraws has carefully crafted with beginner, intermediate, and advanced topics. @twoStraws asks that you program each day and follow the program. The forums are here to help answer questions to help those on this journey. I sense that you are not following @twoStraws' excellent 100 Day program. You come here and dump a load of code, much of it not even related to the problem, and are asking for our help to debug your code on the same day you joined. Maybe this is the idea that I feel deserves criticism. Perhaps, instead, you might consider following the 100 Day program? When you reach the lessons on decoding JSON you'll have a solid understanding of Views, Decoders, Encoders, Codable protocols, and updating data models. @twoStraws has several very detailed lessons that answer the very questions you're asking. This is what you really need, in my opinion. We could help you by pointing you to the right lesson in the 100 Days curriculum, or by asking which part of a lesson gave you trouble. From those lessons, you'll know that JSON is a temporary state. Once loaded into a useful form, perhaps an array of objects, you'll use that to display data in your views. |
|
Also, I wonder if you tried to search the forums before posting your question? Be a nice chap, give it a go! At the top of the forums section is a very useful search bar! Wonder what that does? Ever so curious? Helpful HintTry this! Enter "JSON" into the search bar. Then press the enter key on your keyboard. Go on! Be a devil. |
|
Hi You very close. Where is the JSON file stored? on the internet or in the bundle(the app). You marked the In the
Next look at the method
How the use the data
in
then after
now you can use in example body
I will add the whole code on next post. |
|
|
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 April 28th.
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.