Post

Replies

Boosts

Views

Activity

Reply to Binding a NSSearchField to a NSArrayController
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.
Nov ’21
Reply to Subclassing a NSSearchField
Thx for your answer, and yes, I had to add a selector... Not very intuitive but it is like that. So Now I can manage my item selection and do my filter but I'm looking for how to achieve that. I wrote a message here but no answer yet. Can U help me ? Thx.
Nov ’21
Reply to Subclassing a NSSearchField
Hi, So basically, I just added a NSMenu to my NSSearchField : let theMenu = NSMenu(title: "Filters") let theMenus = ["all", "artist", "title", "album"] for theName in theMenus { let theMenuItem = NSMenuItem(title: theName, action: nil, keyEquivalent: "") theMenu.addItem(theMenuItem) theMenuItem.isEnabled = true } searchField.searchMenuTemplate = theMenu Problem : the items are disabled and I don't know how to enable it : What's wrong ? Thx.
Nov ’21
Reply to Subclassing a NSSearchField
Hi, A few mouths later, I just saw your answer... Thx for that ! I'm back on my project which use the ITLibrary (I'm speaking about it here) Everything works like a charm with my NSSearchField and now I'd like to add a NSMenu to have a more option to filter. I took a look to your link but I'm not sure to understand how to add the NSMenu... I have to set a NSMenu to the cell of the NSSearchfield ? Thx.
Nov ’21
Reply to Binding a NSSearchField to a NSArrayController
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.
Nov ’21
Reply to Adding / Removing items from a NSTableView
Back ! So I have the adding / removing actions. What about filtering ? I'm using a NSArrayController now which has binding capacities. To bind it to the NSTableView, I simply do : tracksListTableView.bind(.content, to: arrayController, withKeyPath: "arrangedObjects", options: nil) Et voila ! I tried to bind the NSSearchField in the same way : searchField.bind(             .predicate,             to: self.arrayController,             withKeyPath: NSBindingName.filterPredicate.rawValue,             options: [.predicateFormat: "col CONTAINS[cd] $value"] But it fails when I start to type in the searchField : Multiline Error setting value for key path filterPredicate of object <NSArrayController: 0x6000036fc2a0>[object class: NSMutableDictionary, number of selected objects: 1] (from bound object <NSSearchField: 0x14c710d90>): [<ITLibMediaItem 0x600001013580> valueForUndefinedKey:]: this class is not key value coding-compliant for the key col. How to fix that ? Thx.
Nov ’21
Reply to Number of item in a NSArrayCollection
Alright, it is working ! But now, how to get an item at index(n) ? In the viewFor tableColumn: NSTableColumn?, the [row] method failed : let theTracks = theArrayCollection.arrangedObjects as! [ITLibMediaItem] let theTrack = theTracks[row] >>> fail ("NSArray element failed to match the Swift Array Element type") Why ? Thx.
Nov ’21
Reply to Number of item in a NSArrayCollection
So I switched my little app with NSTableViews to NSArray to NSArrayCollection. It is working but to get the number of items I still need to use a NSArray for the moment... I'd like to remove it and only use only the NSArrayCollection. So for the viewFor tableColumn: NSTableColumn? (for example), I need to know how many objects are added in the NSCollectionView. I create it programmatically for information, not in IB. Thx.
Nov ’21
Reply to Adding / Removing items from a NSTableView
Thx for your answer. Another method is also to use a NSArrayController to bind programmatically to the NSTableView, right ? With that method, is it easier ? Because from the moment I start to add/delete/filter, it becomes more complicated to reload the datas and get it like it is in the TableView, isn't it ? So I start to change my code for the binding : tracksListTableView.bind(.content, to: _arrayController, withKeyPath: "arrangedObjects", options: nil) Like that, I don't have to reload the datas each time I add a track to the TableView. I just do : _arrayController.add(theTrack) But now I have to change my code to remove the selected tracks... What is the good way ? Thx.
Nov ’21