Hi, I have this code accessing firestore and my loop for getting multiple sets of data.
Thank you in advanced!
Hi, I have this code accessing firestore and my loop for getting multiple sets of data.
Thank you in advanced!
You are checking wether the current count is larger or equals to your variable countDadJokes.
while count >= self.countDadJokes
Then inside the loop you increase the count variable. In my understanding you would want to check if the count is lower than countDadJokes.
With this line:
UserDefaults.standard.setValue(self.dadJokes, forKey: "dadJoke")
you are also overwriting what you changed in the last iteration of the loop.
When you say
Why is this loop not working
please tell us what exactly isn't working.
Probably your test is in the wrong order
while count >= self.countDadJokes {
never occurs, as count = 1 to start
Change with
while count <= self.countDadJokes {
or maybe
while count < self.countDadJokes {