diff options
Diffstat (limited to 'mut/keuze/kies/DataSource.swift')
| -rw-r--r-- | mut/keuze/kies/DataSource.swift | 43 |
1 files changed, 0 insertions, 43 deletions
diff --git a/mut/keuze/kies/DataSource.swift b/mut/keuze/kies/DataSource.swift deleted file mode 100644 index 23c1f8e..0000000 --- a/mut/keuze/kies/DataSource.swift +++ /dev/null @@ -1,43 +0,0 @@ -// -// Sorter.swift -// kies -// -// Created by Thomas Billiet on 11/04/2019. -// Copyright © 2019 Thomas Billiet. All rights reserved. -// - -import Foundation -import Cocoa - -class DataSource: NSObject, NSTableViewDataSource { - var items = [String]() - var sortedItems = [String]() - var matches = [String: String]() - var scores = [String: Float]() - - func updateItems(_ items: [String]) { - self.items = items - self.sortedItems = items - } - - func updateSort(query: String) { - for item in items { - let match = item.lowercased().longestCommonSubsequence(query.lowercased()) - matches[item] = match - scores[item] = Float(match.count) / Float(query.count) - } - - sortedItems = items.sorted(by: { (a, b) -> Bool in - scores[a]! > scores[b]! - }) - } - - func numberOfRows(in tableView: NSTableView) -> Int { - return sortedItems.count - } - - func tableView(_ tableView: NSTableView, objectValueFor tableColumn: NSTableColumn?, row: Int) -> Any? { - return sortedItems[row] - } - -} |
