From 89d259e27d95cafb097704bc6334488086ffcd34 Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Wed, 10 Apr 2019 15:31:14 +0200 Subject: [PATCH] Sort Pool only when listed as Options Normally it's PoolGroup who needs sorting. --- .../Scenes/ProviderPoolViewController.swift | 10 +++++++++- Passepartout/Sources/Services/Pool.swift | 8 +------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Passepartout-iOS/Scenes/ProviderPoolViewController.swift b/Passepartout-iOS/Scenes/ProviderPoolViewController.swift index 47be0cd1..b0d630a9 100644 --- a/Passepartout-iOS/Scenes/ProviderPoolViewController.swift +++ b/Passepartout-iOS/Scenes/ProviderPoolViewController.swift @@ -192,7 +192,15 @@ extension ProviderPoolViewController: UITableViewDataSource, UITableViewDelegate } let vc = OptionViewController() vc.title = pool.localizedCountry - vc.options = groupPools + vc.options = groupPools.sorted { + guard let lnum = $0.num, let ln = Int(lnum) else { + return true + } + guard let rnum = $1.num, let rn = Int(rnum) else { + return false + } + return ln < rn + } vc.selectedOption = currentPool vc.descriptionBlock = { $0.areaId ?? "" } // XXX: fail gracefully vc.selectionBlock = { diff --git a/Passepartout/Sources/Services/Pool.swift b/Passepartout/Sources/Services/Pool.swift index fcf5e5cc..8bc25fa7 100644 --- a/Passepartout/Sources/Services/Pool.swift +++ b/Passepartout/Sources/Services/Pool.swift @@ -26,7 +26,7 @@ import Foundation import TunnelKit -public struct Pool: Codable, Hashable, Comparable, CustomStringConvertible { +public struct Pool: Codable, Hashable, CustomStringConvertible { public enum CodingKeys: String, CodingKey { case id @@ -105,12 +105,6 @@ public struct Pool: Codable, Hashable, Comparable, CustomStringConvertible { id.hash(into: &hasher) } - // MARK: Comparable - - public static func <(lhs: Pool, rhs: Pool) -> Bool { - return lhs.localizedId < rhs.localizedId - } - // MARK: CustomStringConvertible public var description: String {