Fix provider name ordering

Define intrinsecally with Comparable.
This commit is contained in:
Davide De Rosa 2018-10-29 17:44:34 +01:00
parent 571cee7818
commit cced9b018f
4 changed files with 15 additions and 5 deletions

View File

@ -56,7 +56,7 @@ class OrganizerViewController: UITableViewController, TableModelHost {
}() }()
func reloadModel() { func reloadModel() {
providers = service.ids(forContext: .provider) providers = service.ids(forContext: .provider).sorted()
hosts = service.ids(forContext: .host).sortedCaseInsensitive() hosts = service.ids(forContext: .host).sortedCaseInsensitive()
var providerRows = [RowType](repeating: .profile, count: providers.count) var providerRows = [RowType](repeating: .profile, count: providers.count)
@ -172,7 +172,7 @@ class OrganizerViewController: UITableViewController, TableModelHost {
return return
} }
availableProviderNames = names.sorted { $0.rawValue < $1.rawValue } availableProviderNames = names.sorted()
perform(segue: StoryboardSegue.Organizer.addProviderSegueIdentifier) perform(segue: StoryboardSegue.Organizer.addProviderSegueIdentifier)
} }

View File

@ -73,7 +73,7 @@ class ProviderConnectionProfile: ConnectionProfile, Codable, Equatable {
} }
func sortedPools() -> [Pool] { func sortedPools() -> [Pool] {
return infrastructure.pools.sorted { $0.name < $1.name } return infrastructure.pools.sorted()
} }
private func validateEndpoint() { private func validateEndpoint() {

View File

@ -27,12 +27,16 @@ import Foundation
import TunnelKit import TunnelKit
struct Infrastructure: Codable { struct Infrastructure: Codable {
enum Name: String, Codable { enum Name: String, Codable, Comparable {
case pia = "PIA" case pia = "PIA"
var webName: String { var webName: String {
return rawValue.lowercased() return rawValue.lowercased()
} }
static func <(lhs: Name, rhs: Name) -> Bool {
return lhs.webName < rhs.webName
}
} }
struct Defaults: Codable { struct Defaults: Codable {

View File

@ -26,7 +26,7 @@
import Foundation import Foundation
import TunnelKit import TunnelKit
struct Pool: Codable, CustomStringConvertible { struct Pool: Codable, Comparable, CustomStringConvertible {
enum CodingKeys: String, CodingKey { enum CodingKeys: String, CodingKey {
case id case id
@ -69,6 +69,12 @@ struct Pool: Codable, CustomStringConvertible {
return addrs return addrs
} }
// MARK: Comparable
static func <(lhs: Pool, rhs: Pool) -> Bool {
return lhs.name < rhs.name
}
// MARK: CustomStringConvertible // MARK: CustomStringConvertible
var description: String { var description: String {