Using local JSON file for City Sights App

Hi,
I have used Proxyman to copy the JSON file generated in the Module 6 Lesson 12 City Sights App. I would like to modify the App to read the JSON from the App’s resource folder rather than doing an internet request. This will be used as a starting point to display data in another JSON file. I have also looked at the Module 2 Lesson 12 mvvm_demoAPP recipe app but don’t quite see how it is using a local JSON file. I have spent days trying all sorts of things to no avail, so any help would be appreciated.
Thanks

@mark_bresler

Hi Mark,

Do I understand from what you are saying that you are following the City Sights App Module? ie: Module 6 of the iOS Foundations (SwiftUI) course?

Yes,
I am trying to use that as a jumping off point for an app showing service locations in an area.

Have a look at the RecipeList App and see how the local file is retrieved and decoded in the DataService.swift file.

Yes, I have been trying to integrate parts of M2L12 RecipeModel into M6L12 ContentModel. They seem to be handling errors with different techniques, and referring to the arrays with different conventions. I am working through it, and think I am closer, thanks

Trying to determine what is going on and how to fix it.

The 1st line below prints the message, the second still leaves pathString nil. data.json is in the Data folder within the CitySights App. How can I troubleshoot further to see what is going on?

print(“about to get json file”)
let pathString = Bundle.main.path(forResource: “data”, ofType: “json”)

Thanks, Mark

When you dragged the JSON file into your project, it is possible that one of the settings in the dialogue box that was presented, was not set. Most likely the “Add toTargets”. Sample screenshot attached:

If “Add to Targets” was not selected then Xcode will not know about the file despite the fact that it exists in the Application Bundle.

To check, select the data.json file and on the right of your screen in the Inspector panel, make sure that the File Inspector is selected and then look down the screen for the heading titled “Target Membership”. Ensure that there is a checkmark against (in your case) CitySights.

Thank you, that suggestion worked, but now I have a JSON file issue. I will start a new thread on that, thanks again