Contents

hydralo/swiftkeypathsortingretrofit

import Foundation

Example

struct SomeSortableStructure {
    let id: Int
    let isSelected: Bool
    let title: String
    let description: String?
}

struct SorterGuy {
    func sort(_ items: [SomeSortableStructure]) -> [SomeSortableStructure] {
        items.sorted(using: [
            .keyPath(\.title, order: .ascending),
            .keyPath(\.isSelected, order: .descending),
            .keyPath(\.description, order: .ascending),
            .keyPath(\.id, order: .ascending)
        ])
    }
}

Installation

The implementation is quite compact so in most cases it can be just copied to the target project.

Swift Package Manager

dependencies: [
    .package(url: "https://github.com/Hydralo/SwiftKeyPathSortingRetrofit.git")
]

Requirements

  • iOS 10+

Package Metadata

Repository: hydralo/swiftkeypathsortingretrofit

Default branch: main

README: README.md