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.
Asked
Active
Viewed 75 times
0
-
Just an idea: Find the 10 files and hide the other rows. – Willeke Oct 18 '18 at 15:17
1 Answers
2
Set the fetchLimit
on your NSFetchRequest
to be the number you want (10 in your example).

Dad
- 6,388
- 2
- 28
- 34
-
@alfonso-tesauro if this worked for you, please accept it to remove your question from the Open Questions list on SO. If it didn't, a follow up comment to clarify why or what's not working for you would allow us to follow up. – Dad Nov 20 '18 at 02:42
-
This did not totally work for me, because I think I am using a NSTreeController and bindings. I think your solution is valid when using an outline's view datasource and delegate. – Alfonso Tesauro Dec 05 '18 at 15:02
-
If that's the reason then take a look at NSTreeController's superclass which allows you to access the NSFetchRequest that populates the model and the fetch request has the fetchLimit field you need to set. – Dad Dec 05 '18 at 23:05
-
I haven't used this in exactly this setup (bindings) but the documentation implies this should work here also. – Dad Dec 05 '18 at 23:06
-
Sorry I missed the NSTreeController aspect of your question. Looks harder to use in that context. Without a bit more code for context I'm not sure, but it looks like because you're using it in the recents button case you aren't showing the whole hierarchical list but just a flat list and so you could in fact modify the tree control query with the fetchLimit specified as I noted in my comment above (similar to what you do for the search presumably?). – Dad Dec 06 '18 at 22:33