|
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.
|
|
GO FURTHER, FASTER Unleash your full potential as a Swift developer with the all-new Swift Career Accelerator: the most comprehensive, career-transforming learning resource ever created for iOS development. Whether you’re just starting out, looking to land your first job, or aiming to become a lead developer, this program offers everything you need to level up – from mastering Swift’s latest features to conquering interview questions and building robust portfolios.
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.