TGViewer
easy_dev991 easy_dev991 @easy_dev991 · 617 subscribers
Post #230 467
easy_dev991 struct ComplexModel { let name: String let id: Int let price: Double let isActive: Bool let creationDate: Date let websiteURL: URL? let tags: [String] let statistics: [String: Int] let description: String? } /// Выполнить…
#swift #foundation #keypath #hint

Представляю вам KeyPathComparator, доступный с iOS 15.
Решает задачу из опроса на изи)


struct ComplexModel {
let name: String
let id: Int
let price: Double
let isActive: Bool
let creationDate: Date
let websiteURL: URL?
let tags: [String]
let statistics: [String: Int]
let description: String?
}

/// Выполнить работу с массивом и вернуть отсортированный массив
func doWork(with items: [ComplexModel]) -> [ComplexModel] {
// другая логика ...
return items.sorted(using: KeyPathComparator(\.name)) // <- вот
}

/// Выполнить работу с массивом и вернуть отсортированный массив
/// - Parameters:
/// - items: Изначальный массив
/// - order: Порядок сортировки
/// - Returns: Отсортированный массив
func doSortedWork(with items: [ComplexModel], order: SortOrder) -> [ComplexModel] {
// другая логика ...
return items.sorted(using: KeyPathComparator(\.name, order: order))
}
Apple Developer Documentation KeyPathComparator | Apple Developer Documentation A comparator that uses another sort comparator to provide the comparison of values at a key path.
  • 👍 4
  • 🔥 2
More from @easy_dev991
  1. Oct 15, 2026#android #agent #openspec Если завтра все нейросети сломаются, мне будет не важно, потому…
  2. Oct 4, 2026#agent #opencode #question Чтобы ваш кастомный агент мог задавать вопросы как на скриншоте…
  3. Oct 3, 2026#ios #swift #swiftui #animation Чиним дрейф лоадера в SwiftUI
  4. Oct 1, 2026#agent #skill https://teletype.in/@easy_dev991/Vdp8kJPuWEg
  5. Sep 26, 2026#android #test #agent Делаю приложение-дневник тренировок для андроида, и агент пишет/гоня…
  6. Sep 21, 2026#agent #mcp #firebase Собирал сегодня данные по крашам из firebase, чтобы потом спланирова…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →