2

Suppose I have the following objects

class A { 

NSArray *arrayOfB;
}

class B {

NSString *name;

}

Now, I have an array of As like below and each A contains 10 objects of B within its property arrayOfB.

NSArray *arrayOfAs; //contains objects of A

How can I get the objects of A depending upon specific match of name property of Bs inside of A, by using NSPredicate ?

I've tried googling, etc. and even writing various style of NSPredicate but did not succeed. Can anyone enlighten me how to do it?

This is what I tried so far:

NSPredicate *p = [NSPredicate predicateWithFormat:@"(SELF.name BEGINSWITH[c] %@ IN SELF.arrayOfB)",myText];

NSArray *mySearchedArrayOfAs = [arrayOfAs filteredArrayUsingPredicate:p];

But I run into error which says "Unable to parse the predicate".

1 Answer 1

4

I think you need to use ANY operator, like this:

NSPredicate *p = [NSPredicate predicateWithFormat:@"ANY arrayOfB.name BEGINSWITH[c] %@", myText];
Sign up to request clarification or add additional context in comments.

1 Comment

I do not have a setup to check this at the moment. Let me know if this does not work, and I'll delete the answer.

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.