0

I have a "Event" class in Parse DB which has two pointers called "Feature" and "Network". See below for reference:

enter image description here

I want to retrieve objects from Event class which have the selected array of features and in the selected networks. I tried to do the query as below:

func getEventsByFilter(networks: [Network]?, features: [Feature]?,completion: (events: [Event]?, error: NSError?) -> ()) {
    let query = PFQuery(className:"Event")
    query.whereKey("feature", containedIn: features!)
    query.whereKey("network", containedIn: networks!)

However, I get the following error and the query returns all the events in the Events class: [Error]: Caught "NSInvalidArgumentException" with reason "Invalid type in JSON write (MyApp.Network)":

Any suggestions on how to rewrite the query so that I can get events that are in the selected networks and having the features that are selected?

Any help appreciated! Thanks!

2
  • do you have arrays networks and features defined as PFObject ? Commented Mar 18, 2016 at 14:59
  • @MazelTov: Feature and Network are two different classes in my project. They inherit from NSObject and have initialization through PFObject. Commented Mar 18, 2016 at 18:38

1 Answer 1

1

Make sure features and networks are an array of Strings (NSStrings for objC).

Parse keys are always of type String, of either objectID or whatever key value is stored.

EDIT

Forgot to add for "containedIn:" parse will be expecting an Array of Strings as the parameter.

PFQuery *categoryQuery = [PFQuery queryWithClassName:kClassnameCategory];
[categoryQuery whereKey:kKeyCategoryName equalTo:self.listCategory];
[categoryQuery getFirstObjectInBackgroundWithBlock:^(PFObject * category, NSError * _Nullable error) {

The above code [categoryQuery whereKey: equalTo:] is expecting a String for both of the parameter to find a match since all Parse keys are Strings. In the case of containedIn: it would be expecting an Array of Strings.

Sign up to request clarification or add additional context in comments.

1 Comment

Will give this a try and let you know if it resolves my issue. Thanks for the help!

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.