0
votes

I have an NSArrayController which is bound to a class in my Managed Object Context. During runtime the NSArrayController can have a number of different filter predicates applied. At certain intervals, I want to iterate through my NSArrayController's contents regardless of the filter predicate applied to it.

To do this, I set the filterPredicate to nil and then reinstate it after having iterated through my array. This seems to work, but I'm wondering if it's best practice? Should I instead be polling my Managed Object Context manually?

NSPredicate *predicate = nil;
predicate = [myArrayController filterPredicate];
[myArrayController setFilterPredicate:nil];
for(MyManagedObject *object in [myArrayController arrangedObjects]) {
    // ...
}
[myArrayController setFilterPredicate:predicate];
2

2 Answers

0
votes

If you're only interested in getting all Foo instances with no filter then iterating through them programmatically, why not use an NSFetchRequest directly?

It's easy enough to use sort descriptors in your fetch request if you're asking for your controller's -arrangedObjects for that alone.

4
votes

You can retrieve all the content from an array controller, independently of the filter predicate applied, using the content selector:

[myArrayController content]

You don't need to reset the filter predicate at all.