RobertGummesson / BuildTimeAnalyzer-for-Xcode

Build Time Analyzer for Swift
MIT License
4.3k stars 260 forks source link

Sorting by filename #78

Closed DmIvanov closed 6 years ago

DmIvanov commented 6 years ago

Not sure if you agree with all the changes, but I'll try to explane them.

The original idea was to add standard sorting by filename to the table. I found it might be quite convenient to work file by file.

There were already several variants of data source in the ViewController (dataSource, filteredData, perFunctionTimes, perFileTimes), so adding one more wasn't an option. So I decided to incapsulate all the processing over the data array to a separate class (ViewControllerDataSource), store only one original array of items and apply all the aggregating, filtering and sorting dynamically if necessary. In my opinion it makes code and the logic cleaner and easily lets extend processing functionality (other operations under the data array if necessary).

Unfortunately I had to convert CompileMeasure to an objC class for being able to easily apply an array of sort descriptors. I couldn't find easy and elegant way to apply several sorting functions to swift array without a lot of pain (didn't want to implement something like http://chris.eidhof.nl/post/sort-descriptors-in-swift/). I thought that inheriting the model from NSObject and double casting the array (to NSArray and back to swift array) is not such a big deal considering the ability to use good old sort descriptors (which are built in to NSTableView)

All the basic functionality of ViewControllerDataSource is covered with tests.

RobertGummesson commented 6 years ago

Nice work! I like it. We can live with the objc bits so let's bring this in.