Loop behaves differently in a segment switch!

Hey All,

I am stumped trying figuring this one out. I have the following for loop in the viewDidLoad:

for pass in lection {
            
            if pass.specialDay == theDate && pass.day == "AfterChristmas" && theMonth == "12" {
                year.text = pass.year
                titleName.text = pass.title
                specialAdd = true
            }
            else  if pass.week == theWeek && pass.day == prayerDay {
                year.text = pass.year
                titleName.text = pass.title
                specialAdd = false
            } // end if
        } //end single pass of loop

It works exactly as expected in viewDidLoad it chooses the first if statement, but when this same loop is placed in a segment switch in the same viewController, it always defaults to the second if statement.

When I query the pass.specialDay it returns the record in the array pointing to the second if statement not the correct record.

Please correct my logic if I am missing something, but when the for loop runs, it will loops through the entire arrary looking for the first if statement, and if it does not find it, it will then run again looking for the second if? Or will both statements be evaluated by each pass of the loop?

If is is the latter, I wonder why it correctly grabs the right data in the viewDidLoad?

Clearly, I need to walk away and look at this again later! Lol

Thanks!
Blessings,
—Mark

I find that testing is an art!

I finally discover by a lot of trip and error that in fact the if statements are behaving exactly as they are supposed to behave. So that part is solved. Duh.

When i am trying to figure out now is when I query the array to present the data, it grabs it from a different record on the first if statement and the correct record for the second. Ug!

More testing!
Blessings,
—Mark

Trial and error testing is the magic words.

Found the bug and it is humming along now.

So much code… :slight_smile:

Blessings,
—Mark

1 Like