views:

48

answers:

1

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];
A: 

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.

Joshua Nozzi