I utilized a table view, bound to an NSArrayController, who’s data is being stored in the Shared User Defaults in my application.
The table only has a single column.
I’m wondering what the easiest way would be to sort the values alphabetically, ascending order? Can this be done with binding? Or should I add some type of sort code to the “apply preferences” function I have in my application?
Most of the examples I’m finding for this are all OBJ C.
set anArray to current application's NSArray's arrayWithArray:arrayList
set sortDesc to current application's NSSortDescriptor's sortDescriptorWithKey:sortField ascending:sortAscending selector:"caseInsensitiveCompare:"
anArray's sortedArrayUsingDescriptors:{sortDesc}
Sorry, I am not following. BTW, if you have Shane Stanley’s book, he has projects on the arrayController class in which he illustrates sorting tables using an array Controller.
So you create sort descriptors and tell your array controller to use them. Something like:
set theDescriptor to current application's NSSortDescriptor's sortDescriptorWithKey:theKey ascending:ascendingOrder
genreArrayController's setSortDescriptors:{theDescriptor}
I actually decided to just enable the column header, and I set it to be case insensitive sortable via that (I followed Shane’s book). This is actually better as it allows the user to choose if they want it sorted or not.
My only issue now is that it’s not writing the sorted version out to the shared user defaults. Is there a “continuously updates” for the array controller?