M
M
Mirzamorph2019-07-10 17:36:25
iOS
Mirzamorph, 2019-07-10 17:36:25

How to implement data storage in an ios mobile application with questions and answers to them?

Good afternoon!
I'm new to mobile development and would like to know how best to store data in an application.
Mobile application based on ios, using the swift 5 programming language.
The application will consist of registration (which will be implemented using firebase) and questions with answers to them.
For example, suppose the question is "What shape is the earth?" and below the answers will be presented in the form of buttons "Round", "Square", "Flat", "Diamond-shaped".
There will also be other types of questions, for example, the question about the shape of the earth is the same, but instead of the correct answers, there will be a text label where you will need to enter the answer.
The question is what is the best way to implement storing these questions with answers on the device, I have found several options so far, but I do not know which one is better:

  • plist file
  • json file

Perhaps there are better options.
That is, if you implement a json file, it will look something like this (I'm still thinking):
{
   "id": "1",
   "title": "Какой формы земля?",
    "type": "buttons",
    "right-answer": "Плоская",
    "wrong-answers": "Круглая, Квадратная, Ромбовидная"
}

And then parse all this json depending on the type field.
UPD:
Questions and answers will be edited only by the developer, that is, in theory, in order for the user to see new questions, he will need to update the application in the App Store.
UPD2: Where is the best
place to store the json file?
On the server or in the application itself?
All the same, requests to a file that lies with the application itself will be faster than to a remote server, but in the first case it is possible to change something in case of an error (or break everything).

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Vorobei, 2019-07-10
@Mirzamorph

Of course JSON , don't even hesitate.
The architecture is correct, a little grind:

{
   "id": "1", //  всё отлично
   "title": "Какой формы земля?", // можно question
   "type": "buttons", // Если это стиль отображения, тогда сделай массив. Если тип вопроса - всё ок
   "answers" {
      "correct": "Плоская"
      "incorrect": ["Круглая", "Квадратная", "Ромбовидная"]
   }
}

Updated hierarchy for answers, wrong answers in an array. Correct answers would also be nice in an array.
If questions are rarely added, then locally . For the sake of the potential opportunity to fix the error, it’s not worth tormenting http)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question