Search code examples
macoscocoansoutlineviewnstreecontroller

In a macOS Cocoa application, How to show only the first 'x' elements that match a NSPredicate in a NSOutlineView populated with a NSTreeController?


I am developing a macOS proof of concept project. I have, in the main window, a NSOutlineView populated with a NSTreeController via Cocoa bindings and Core Data. Under the NSOutlineView, I have a search field and a "Recents" button, a bit like Xcode has in the project navigator. My Core Data model object has a "modifiedAt" property and, when the user selects the "Recents" button, I would like to show only the last 10 modified files in the OutlineView. Any suggestions on how to achieve that ? Thank you in advance for any help.


Solution

  • Set the fetchLimit on your NSFetchRequest to be the number you want (10 in your example).