After spending several hours on trying to fix a bug in my app, here I come to ask you for help and being able to continue. Here is my case (I'll keep it as short as possible):
1- I make a small quiz app, where I retrieve 20 questions from an API of Open Trivia's website. The first image is where players fill their names. It is in this viewController where I call the GetAPIINfo class to get the data from the api and load it in my global variables
2- Once the game starts, you can see that what is in the iPhone's screen, corresponds to what it was retrieved from the API. This corresponds to another view controller called "QuizViewController". See image 2
3- Once all the 20 questions have been asked (10 per player), the "game over" screen prompts on the screen (Image 3).
4- What I want to do, is to restart the match once the "Rematch" alert controller button is pressed. When it is pressed, I call again the API and load new set of 20 questions. In image 4 you can see what I tried to do (among other stuff before this) in order to reload my QuizViewController
5- I am able to start a new game, with the scores reset to zero and the players names are the same. Also, you can see in the console in image 5 that I successfully loaded a new set of 20 questions. The problem: the game still shows the first set of 20 questions. Basically I'm playing again with the same set of questions and answers even though I loaded 20 new questions.
6- I have checked in the QuizBrain file (where the values of the questions and answers are stored) that my value "quiz" did not overwrite with the new values (See Image 6) even if I deleted the global variable "quiz" everytime I press the "Rematch" button.
So here I am, asking you guys to share with me your wisdom and knowledge in order to solve this problem. Thanks in advance for your advice.
I have already tried with several options like this one, or this one, among many others with no success so far.
TL;DR: I make a quiz app that loads 20 questions from an API, I want to reload my view with a new set of 20 questions, but I still see and play with the first set of 20 questions even if I loaded a new set of questions but apparently they are not being stored. Greetings.
After you click rematch the API call will be triggered. You have to wait for this API call to finish before you show new set of questions to the user. If not, you would be showing older data.