How to sort columns of my NSTableView ?

I want to sort some columns in my table view…
Needless to say that to implement sorting, your data source data should be sortable…
First - assuming you want to trigger sorting on user click in the column headers - you need to associate a
delegate to your table view.
Then the delegate class must implement the instance method:

- (void)tableView:(NSTableView*)tableView mouseDownInHeaderOfTableColumn:(NSTableColumn *)tableColumn
Somewhere in your delegate instance, you should maintain variables keeping trace of the sort order: unsorted, ascending, descending. If you have a default sort order, the unsorted status may not be needed, but don't forget to initialize the sort order somewhere. the awakeFromNib method of the window controller is a good candidate for that. You may want to implement reading back the sort order from some defaults in it.
In the
mouseDownInHeaderOfTableColumn, you can track your status variable(s) (you may need one for each sortable column - stored in a NSArray or NSDictionary as you like).
Retrieve the column identifier with
[tableCoumn identifer], update your state variable and sort your data source according to the new settings.
You can change the small indicator with

[tableView setIndicatorImage:[NSImage imageNamed:(
mySortIsAscending)? (@"NSAscendingSortIndicator"):(@"NSDescendingSortIndicator")] inTableColumn:tableColumn] ;

Note you may pass
nil to clear the indicator (for unsorted status).
Eventually call
[tableView setNeedsDisplay:YES] to post a view refresh request.
Useful methods to sort
NSArray:
- (NSArray *)sortedArrayUsingFunction:(int (*)(id, id, void *))comparator context:(void *)context;
- (NSArray *)sortedArrayUsingFunction:(int (*)(id, id, void *))comparator context:(void *)context hint:(NSData *)hint;
- (NSArray *)sortedArrayUsingSelector:(SEL)comparator;
Of course standard C qsort may also help…