开发者

Temporarily disabled NSArrayController filterPredicate, or consult ManagedObjectContext?

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 arr开发者_如何学运维ay. 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];


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜