I am building a recipe app and i have all my recipes raw data (ingredients, recipes, and instructions) are stored on a singe data.swift file. The problem is the file is about 3000 lines long for 100 recipes. It is easy to access the data because it on the app but is it going to slow down the app with all the data inside the app rather than from a database? Would it be better to put the data in a json file or a database? Also, if i go with a database, i have an image for each recipe, would i need to store the images on the database as well, rather than they be in the app in the assets folder?
You don’t need a database at all.
Since you already have a JSON file configured then obviously you know how to update it if you need too. With that in mind, the simplest way is to host that file somewhere and the best place is Github. There you can change the file whenever you want to update it with new recipes or amended recipes and the App will pick up the changes once you create the necessary code to remotely retrieve that JSON file.
It’s much easier than having the data stored with the App because if you store it as a file in the App then any change to the data will mean that you need to submit a new version of the App with the revised JSON file. Far too messy.
All you need to do is remotely retrieve the JSON file and that’s easy enough to do with a URLSession. Chris Ching has a number of Apps for which there is a course that shows you how to do that.
Check out his learn.codewithchris.com site.
Thanks for the reply Chris. I just wanted to clarify that right now, all my data is on the data.swift file in my app (one for recipes, one for categories). I realize that having that much info in one file may slow down my app and make it harder to add new recipes without updating the app. But i was told by someone on StackOverflow that either a database or JSON would be more efficient. Im not overly familiar with JSON but i know a little. I would like to know where i can go to assist me on how to place my data is a json, then how i can use it for my app, like how i can access the data from my app. I have a website where i could host it but don’t know how or Github is fine too. Can you point me to the particular app tutorials Chris Ching has that can help me?
What is your preference? Storyboard or SwiftUI?
There is a Recipe App that Chris Ching builds using SwiftUI.
It’s in the course titled iOS Foundations (SwiftUI). See the attached screenshot. You will need to subscribe to CWC+ to get access to it which you can do on a month by month basis. You can discontinue your subscription at any time.
If you are new to SwiftUI then I would suggest you start the course at the beginning and work through it so that you get a good grounding in the SwiftUI framework.
The Recipe App is Module 5 and it uses a JSON file (embedded in the App) as the data source for the recipes and the images for the recipes are stored in the assets catalogue. This does not solve your need for a database but at least you are building your JSON skills.
Module 6 is the Learning App which includes retrieving JSON code from a remote location so that will give you the skills in performing Network calls.
This sounds perfect. I will give this a try. I am not a NOVICE in SwiftUI and SwiftUI is my preference for any project i do. I have one on the AppStore now called #yolo but you will need to put in this: “Yolo Fitness” in your search. Thank you for your help and once complete, i will let you know if this solves my problem. Have a great day, Chris!