Bug 17758 - NSArray.Sort() method does not have overload for Sort(NSSortDescriptor[] sortDescriptors)
Summary: NSArray.Sort() method does not have overload for Sort(NSSortDescriptor[] sort...
Alias: None
Product: Xamarin.Mac
Classification: Desktop
Component: Library (Xamarin.Mac.dll) ()
Version: 1.6.19
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Aaron Bockover [MSFT]
Depends on:
Reported: 2014-02-13 14:51 UTC by Jon Goldberger [MSFT]
Modified: 2014-02-13 15:34 UTC (History)
2 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Comment 1 Jon Goldberger [MSFT] 2014-02-13 14:52:50 UTC
I'm trying to sort my table columns following instructions at https://developer.apple.com/library/mac/documentation/cocoa/Conceptual/TableView/SortingTableViews/SortingTableViews.html

So far I have:

* Create a sort descriptor for my column - OK

NSTableColumn nameColumn = NSTableColumn("Name");

NSSortDescriptor nameSort = new NSSortDescriptor("Name", true);

nameColumn.SortDescriptorPrototype = nameSort;

* Add the method in my NSTableViewDataSource - OK (the method is called when clicking the header of the column)

public override void SortDescriptorsChanged(NSTableView tableView, NSSortDescriptor[] oldDescriptors)
NSSortDescriptor[] newDescriptors = tableView.SortDescriptors;

//[peopleArray sortUsingDescriptors: [tableView sortDescriptors]]; ??


But, I can't find the "sortUsingDescriptors" anywhere. The NSMutableArray doesn't have it as it happens in Mac.

Any help? How this should be done with MonoMac? Is there any other way to do it?
Comment 2 Miguel de Icaza [MSFT] 2014-02-13 15:25:54 UTC

For now the code must implement its own sorting of its own data, using the provided descriptors.

While we can add the API (and we will), the sorting would only assist provided that your storage is an NSMutableArray, which is not a common storage system in C#.

What the code needs to do is use the standard sorting routines in C#, but use the sort descriptors to determine how the sorting should take place.

The basics are simple, the NSSortDescriptor details whether the sorting should be ascending or descending as well as the key to compare.

You would use the key to determine which field to compare to, and to use in your own comparison function.

That said, we added the API just now, but it wont be of much use, unless you store your data in NSMutableArrays.