I am querying an SQL database but for some reason the result items are coming back randomly. Here's my code:
for items in searchFriendEmailArrayNew {
        let query = table.query(with: NSPredicate(format: "email == '\(items)'"))
        query.selectFields = ["isriding"]
        query.read { (result, error) in
            if let err = error {
                print("ERROR ", err)
            } else if let items = result?.items {
                for item in items {
                    let theItem = item["isriding"] as! Bool
                    let newItem = String(theItem)
                    self.searchFriendIsRidingArray.add(newItem)
                    loopCount = loopCount+1
                    if loopCount == self.friendsArray.count {
                        self.tableView.reloadData()
                        self.activityIndicator.isHidden = true
                        self.activityIndicator.stopAnimating()
                    }
                }
            }
        }
    }
The searchFriendEmailArrayNew is an array of email addresses so that when I query the database table it uses the email to look up that user. The array is always consistent and in the same order:
- user1@email.com
 - user2@email.com
 - user3@email.com
 - user4@email.com
 
And the query is always done in that order.
I then query the selected field of the user, in this case I am querying the 'isriding' field. This field is a bool returning true or false.
However, when I get to 'for item in items' the results come back in a random order. For example let's say user1 'is riding = true' but all the other users false, the items returned can look like this:
- isriding false
 - isriding false
 - isriding true
 - isriding false
 
If I then run the code again it might look like this:
- isriding true
 - isriding false
 - isriding false
 - isriding false
 
Can anyone advise as to why they might be coming back in a random order even though when the table is queried it is always queried in a specific order.
Thanks for any help.