Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add JSON file to app

Tags:

ios

swift

I would like to add a JSON file to my app and read from this file at runtime. I have looked online for how to do this, but most of the information is concerned with reading the file. I cannot find any information online about how to make the file available at runtime. Most of the stuff online seems to be reading from a bundle, but I have no idea how to create a bundle or how to add a JSON file to it. Can someone provide some information?

like image 456
Max Avatar asked Sep 23 '15 03:09

Max


1 Answers

This is a fairly simple task. This is how you would do it:

  1. Create a new folder in finder. Name it MyProject. You can name it anything.
  2. Drag and drop you .JSON file into it.
  3. Rename the folder to MyProject.bundle. You shall see below alert.
  4. Click on "Add" button.
  5. Finally, drag and drop this to your Xcode project and use it. From your description, I believe, you already know how to read .JSON from it.

enter image description here

PS: Although, as Gurtej suggested, you can directly add your .JSON into project an read it from there. My post answers your query as how we create a bundle and add files to it.

like image 97
Abhinav Avatar answered Sep 26 '22 00:09

Abhinav