'Parse-Swift Check multiple columns (Compound / OR statement)

I have a table where I have three columns in my database that can contain a String, I need to check all three and return that row of data if ANY of those columns have what I'm looking for.

For example the string I'm looking for might appear in the first column (firstArtist) for one row but could appear in the second column (secondArtist) and possibly in the third column (thirdArtist) for another.

I'm using Parse-Swift not Parse.

Wallpaper is my model class.

I've tried something like this:

var testString = "example"

let query = Wallpaper.query()
            .where(Wallpaper.CodingKeys.firstArtist.rawValue == testString)
            .where(Wallpaper.CodingKeys.secondArtist.rawValue == testString)
            .where(Wallpaper.CodingKeys.thirdArtist.rawValue == testString)

But nothing gets retrieved from the database, I assume this is because since it doesn't find anything with the first where statement it doesn't include those results in the rest which could contain the string.

The following works:

let query = Wallpaper.query()

       query.findAll { result in
            switch result {
            case let .success(wallpapers):
                var test: [Wallpaper] = []
                for item in wallpapers {
                    if item.artists.contains(testString) {
                        test.append(item)
                    }
                }
                completion(.success(test))
            case let .failure(error):
                completion(.failure(error))
            }
        }

But the looping through the results and manually filtering them causes my app to take more that ten seconds to load the results, since I'm grabbing everything which isn't ideal.

How can I do the equivalent of a OR statement / Compound statement within Parse-Swift? I've looking through the documentation but I cant find and examples of this.

I found this repository Github Parse-Swift Playground Which contains examples from the Parse-swift Devs themselves but nothing.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source