Binding a NSSearchField to a NSArrayController

Hi,

Is it possible ? How ?

I have a NSTableView binded to a NSArrayController programatically and I’d like to filter it with a NSSearchField with criteria or not.

Thx.

Replies

Hi,

Back on this post.

So I took a look on the Internet and I found some interesting sources.

I found how to bind the NSSearchField :

searchField.bind(.predicate, to: arrayController, withKeyPath: NSBindingName.filterPredicate.rawValue, options: [.predicateFormat: "title CONTAINS $value"])

And as U can see it works like a charm when I search in the ITMediaLibItem object title :

But I'm not familiar with the notation and I didn't find all the possibilities. I notice if I had [cd] to the CONTAINS keyword, whatever the case the string is which is great :

What are the other possibilities ?

Thx.

Hi,

I'm still stuck on that.

I tried to add another condition OR :

searchField.bind(.predicate, to: arrayController, withKeyPath: NSBindingName.filterPredicate.rawValue, options: [.predicateFormat: "(title contains[cd] $value) OR (artist.name CONTAINS[cd] $value)"])

It works :

Bur it is not what I'm looking for. I'd like to concatenate to have all the tracks which contains the string in the artist, title and album, like in the Music app :

How to do that ?

Thx.