|
Dear kind people- I have multiple JSON files, but would like to read a specific JSON file when user selects from a list (.i.e., Picker). Is this possible and if so how might it be done. The reason for loading only one JSON at a time is due to the large number and sizes of the JSON files. I have tried many permuations to pass fileName to the following code "var datas: [Data] = load(fileName)". But all have failed. -Thank you. |
|
Yep, it can be done easily. But we need to see more of your code to figure out the best way to assist you. |
|
Steve would like someone to code for him, or would prefer learning some techniques. It's hard to tell....
It would be easier to help you learn how to code SwiftUI and read data from JSON files, if you provide some code! Please amend your query above. Add one or two of your permutations. Add some comments to your code so we can see what you clearly understand, and where your knowledge gap may be. Help us help you! |
|
|
|
Above code gives error "Variable 'specs' was never used; consider replacing with '' or removing it." Unable to correctly update fileName so that program loads user selected JSON file. I am relatively new to SwiftUI and trying to wrap my head around Declarative coding. Thank you for taking time to review! |
|
Steve we encourage you to explore the many lessons that @twoStraws has provided for reading JSON from your application's bundle. Here's an example where I modified code allowing a user to select one of three files stored in the bundle.
Here's a sample file containing Album data. Name this file Beatles.json and drop it in your bundle.
|
|
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 October 1st.
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.