SetFilterPredicate on NSArrayController does not work if it is in the "Automatically reorder content" section,

I have a classic CoreData application that maps it to an NSTableView with a binding (everything is done with Xcode 4.2).

Working fine until I decide yesterday to check the "Auto-reorder content" attribute inspector for the ArrayController in the Attribute Inspector. Now, when I try to set the filter predicate on it, I get:

[<_NSFaultingMutableSet 0x102b65950> addObserver:forKeyPath:options:context:] is not supported. Key path: name 

Keep in mind that without this option it works fine: the predicate is good, and the controller filters the managed content correctly, and only the entity that matches the predicate is displayed in the table view.

Of course, I could just turn off this "automatic reordered content", but it is useful for maintaining the sort order in case of changing entities. If I edit one entity, the β€œdate change” will change, and since my sort order is in that date, I want the TableView to automatically rewrite the row. And he does this with this option, but, alas, with the added error "addObserver is not supported."

_NSFaultingMutableSet comes from the many relationship in the corresponding object, hence the Set. Maybe "Auto Resrange Content" is not compatible with "setFilterPredicate" with many relationships?

Anyone having a similar problem? Internal error of NSArrayController?

Note : the predicates that cause the problem are of the form

 name CONTAINS[cd] %@ OR ANY aliases.name CONTAINS[cd] %@ 

or

 ANY tags.name CONTAINS[cd] %@ OR ANY tags.aliases.name CONTAINS[cd] %@ 

it seems that "ANY" causes some conflict ...

+4
source share
1 answer

Found a solution with the comment above on SUBQUERY.

Hold the parameter "auto resrange content", but change the predicate to:

 name CONTAINS[cd] %@ OR SUBQUERY(aliases, $anAlias, $anAlias.name CONTAINS[cd] %@) .@count != 0 

and

 SUBQUERY(tags, $aTag, $aTag.name CONTAINS[cd] %@) .@count !=0 OR SUBQUERY(tags, $aTag, $aTag.aliases.name CONTAINS[cd] %@) .@count !=0 

respectively.

The predicate was probably wrong, I had not encountered other problems before.

+4
source

Source: https://habr.com/ru/post/1384102/


All Articles