0

When the user searches for a category I need all the arrays that contain that same category to appear + the other categories that are in that respective array.

Once the user has chosen ["Apples", "Oranges", "Limes"] I want to compare which array (out of many) that I queried contains Apples, Oranges or Limes. This can be one array or this can be many arrays.

These are the arrays I'm adding the values to:

 var categoryNeeded = [AnyObject]()  //The user creates this one and adds values to it

 var categoryArr = [AnyObject]() //The Parse arrays are added here:

I have a simple Parse query function.

var query : PFQuery = PFUser.query()!
query.whereKey("contacts", containsString: "\(categoryArr)")
query.findObjectsInBackgroundWithBlock { (objects, error) -> Void in               
    if let objects = objects as [PFObject]! {
        for object in objects {            
            self.categoryArr.append(object["contacts"] as! AnyObject)
            print(self.categoryArr)
        }
    }
}

The 2nd line is suspect:

query.whereKey("contacts", containsString:  "\(categoryArr)")

When querying with that line, I get this error (without a crash):

2016-01-23 15:53:47.508 CC[28514:5733236] [Error]: $regex only works on string fields (Code: 102, Version: 1.11.0)

Without the whereKey line, I get all the values and it prints them. I just can't figure out how to compare and check for matches between the two arrays which ultimately gives the matching arrays. Is there a Swift method that does that?

1 Answer 1

1

You should not use containsString but rather containedIn:

query.whereKey("contacts", containedIn: categoryArr)
Sign up to request clarification or add additional context in comments.

1 Comment

Just an addition to this already simple answer, if you're wanting realtime (or as near as) when it comes to speed, then it'd be best to consult the Accelerate framework (but this is pretty much only for high-capacity work such as mathematical waveforms)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.