Taylor
Taylor

Reputation: 29

Parse Query Contains Non-Exact String

In my Parse Class, I have a column of Names. I would like to query for all names that contain searchString = "om". The query should return all names that contain "om" such as `Tom, Dom, Rom, etc.)

I've tried:

searchString = "om" // something non-exact
var query = PFQuery(className: "NamesClass")
query.whereKey("Name", contains: searchString)
query.findObjectsInBackgroundWithBlock {

but Parse doesn't accept contains as a search parameter.

Seems like queries only accept exact strings

Upvotes: 1

Views: 662

Answers (1)

rickerbh
rickerbh

Reputation: 9913

For substring matching, you should be using whereKey:containsString:

searchString = "om" 
var query = PFQuery(className: "NamesClass")
query.whereKey("Name", containsString: searchString)
query.findObjectsInBackgroundWithBlock {

That should return any NamesClass object where Name has a substring equal to "om". So, Tom, Dominique, and Thomas will be returned. Frank won't.

Upvotes: 4

Related Questions