0

I am developing a Mac app which uses Core data. I am using NSOutlineView and NSTreeController to bind data on view.

You can assume the structure of my data as

  • Parent Item 1
    • Child Item 1
    • Child Item 2
    • Child Item 3
  • Parent Item 2
    • Child Item 4
    • Child Item 5

I am applying a fetchPredicate to my NSTreeController to filter the data successfully. On the other hand, the fetchPredicate is applied only to the first level of the data (to parent Items).

I need a method which I can apply a fetchPredicate also to the child items. For example if my criteria matches to Child Item 1 and Child Item 4 the result should be

  • Parent Item 1
    • Child Item 1
  • Parent Item 2
    • Child Item 4

Any help will be appreciated.

emreoktem
  • 2,409
  • 20
  • 36
  • So what exactly is your question? What is an issue that you have difficulty with in regard to filtering children items? – El Tomato Jun 07 '16 at 10:59
  • Thanks for replying. As I mentioned in my question I am applying a filterPredicate to NSTreeController. For example NSPredicate(format: due_on =< %@", endDate!). But this filter is applied only to the parent items but not to the child items. I still continue to see some child items which doesn't match to this criteria. What I need is to apply my filter only to the second level. Again thanks. – emreoktem Jun 07 '16 at 11:02
  • 1
    You're applying a fetch predicate. NSTreeController doesn't support a filter predicate. NSTreeController fetches the top level objects and uses the children relationship to get the children. If you want to filter the children you have to do some programming. – Willeke Jun 07 '16 at 12:50
  • @Willeke thanks for replying. I'm ok to do any programming but I couldn't find a point to interrupt while NSTreeController creates the child nodes from core data. – emreoktem Jun 07 '16 at 12:53
  • Search SO for 'NSTreeController filter'. – Willeke Jun 07 '16 at 13:30
  • @Willeke I've already searched for NSTreeController filter and found fetchPredicate property for it. As I mentioned in my question, my problem is the filter is applied only to the root objects (parent 1 and parent 2 in my above example) but not to the Child items. Thanks. – emreoktem Jun 07 '16 at 13:49

1 Answers1

0

You're applying a fetch predicate. NSTreeController doesn't support a filter predicate. NSTreeController uses the fetch predicate to fetch the top level objects and uses the children relationship to get the children. The children aren't fetched and the fetch predicate is not used to get the children.

Solution 1: implement a calculated property filteredChildren, like in this question: Filtering A Tree Controller and mentioned in this unrelated answer: Is it possible to bind an NSTreeController to an NSOutlineViewDataSource?

Solution 2: use a data source instead of bindings, also mentioned in the above answer.

Community
  • 1
  • 1
Willeke
  • 14,578
  • 4
  • 19
  • 47