April 2015
Intermediate to advanced
556 pages
17h 47m
English
In Chapter 7, you populated a table view by implementing the data source methods. You might have wondered at that time how you could implement this sorting behavior in SpeakLine.
Recall that clicking on the table column headers updates an array of NSSortDescriptor objects, which the array controller then applies to reorder its content. You can sort any array of NSObject-based objects yourself using the following method on NSArray:
func sortedArrayUsingDescriptors(sortDescriptors: [AnyObject]) -> [AnyObject]
When is the appropriate time to sort? When the user clicks on the header of a column, an optional NSTableViewDataSource method will be called:
optional func tableView(tableView: ...