views:

51

answers:

1

Hi there,

i struggling around NSFetchRequest these days. My data model look like this:

Post <->> Category

Now i need a fetch request to get all posts where the category.name attribute is not "xxx". Looking at the documentation for NSFetchRequest is should be:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"NONE category.name == %@", categoryName]

But this results in an empty list (the request is used by NSFetchedResultsController in an UITableView.

The docs say:

NONE Specifies none of the elements in the following expression. For example, NONE children.age < 18. This is logically equivalent to NOT (ANY ...).

If i invert my predicate to

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ANY category.name == %@", categoryName]

the list contains exactly the objects i want to be excluded from that list.

What am i missing here?

thanks in advance

A: 

The predicate form you have is correct.

The simplest explanation is that you have no objects that match the "@"NONE category.name == %@" predicate. That would explain why the inverse works.

I suggest that you:

  1. Log the predicate with NSLog and see what the predicate actually is each time
  2. Fetch all Post objects compare the count of objects returned with the count of objects returned by the "ANY" predicate. If they are the same then...
  3. ...log the category.name values to see if any of them do match the "NONE" predicate.

I think that should allow you to find the problem.

TechZen