From dfeffa09356821b3bab11d4396cc20030b230eb7 Mon Sep 17 00:00:00 2001 From: Dariusz Rybicki <dariusz@elixxir.io> Date: Fri, 9 Dec 2022 12:55:02 +0100 Subject: [PATCH] Remove broken IndexedListCollator --- .../Helpers/IndexedListCollator.swift | 53 ------------------- 1 file changed, 53 deletions(-) delete mode 100644 Sources/ContactListFeature/Helpers/IndexedListCollator.swift diff --git a/Sources/ContactListFeature/Helpers/IndexedListCollator.swift b/Sources/ContactListFeature/Helpers/IndexedListCollator.swift deleted file mode 100644 index 249af6fa..00000000 --- a/Sources/ContactListFeature/Helpers/IndexedListCollator.swift +++ /dev/null @@ -1,53 +0,0 @@ -import UIKit -import XXModels - -public protocol IndexableItem { - var indexedOn: NSString { get } -} - -class IndexedListCollator<Item: IndexableItem> { - private final class CollationWrapper: NSObject { - let value: Any - @objc let indexedOn: NSString - - init(value: Any, indexedOn: NSString) { - self.value = value - self.indexedOn = indexedOn - } - - func unwrappedValue<UnwrappedType>() -> UnwrappedType { - return value as! UnwrappedType - } - } - - public init() {} - - public func sectioned(items: [Item]) -> (sections: [[Item]], collation: UILocalizedIndexedCollation) { - let collation = UILocalizedIndexedCollation.current() - let selector = #selector(getter: CollationWrapper.indexedOn) - - let wrappedItems = items.map { item in - CollationWrapper(value: item, indexedOn: item.indexedOn) - } - - let sortedObjects = collation.sortedArray(from: wrappedItems, collationStringSelector: selector) as! [CollationWrapper] - - var sections = collation.sectionIndexTitles.map { _ in [Item]() } - sortedObjects.forEach { item in - let sectionNumber = collation.section(for: item, collationStringSelector: selector) - sections[sectionNumber].append(item.unwrappedValue()) - } - - return (sections: sections.filter { !$0.isEmpty }, collation: collation) - } -} - -extension Contact: IndexableItem { - public var indexedOn: NSString { - guard let nickname = nickname else { - return "\(username!.first!)" as NSString - } - - return "\(nickname.first!)" as NSString - } -} -- GitLab