user4951
user4951

Reputation: 33090

Creating Predicate to Test the Number of Relationship

Say I have a Business object in core data. The Business object may or may not have phones.

I want to create an NSPredicate object where only Businesses with Phones would work.

How would I do so?

    NSPredicate * thePredicate5= [NSPredicate predicateWithFormat: @"Phones.count > 0"];

or what?

Upvotes: 1

Views: 135

Answers (1)

Jiri
Jiri

Reputation: 2206

NSPredicate * thePredicate5= [NSPredicate predicateWithFormat:@"NONE Phones == nil"];

or

NSPredicate * thePredicate5= [NSPredicate predicateWithFormat:@"ANY Phones != nil"];

I didn't know the answer when I first read your question but it caught my attention. I read the documentation and did some experimenting on one of my projects (iphone app that uses Core Data and sqlite) and the attached code seems to do what you wanted, but I cannot guarantee that it is the correct solution.

Upvotes: 2

Related Questions