Skip to content

Instantly share code, notes, and snippets.

View AKoulabukhov's full-sized avatar
🔮
Hello, SPACE!

Alexander Kulabukhov AKoulabukhov

🔮
Hello, SPACE!
View GitHub Profile
@calda
calda / SortDescriptor.swift
Created July 20, 2018 00:45
SortDescriptor.playground
import Foundation
// MARK: SortDescriptor
/// Type-erased Sort Descriptor (can store multiple in the same array
/// regardless of the underlying KeyPath
public struct SortDescriptor<Element> {
private let comparator: (Any, Any) -> Bool
@calda
calda / SortDescriptor.swift
Created July 20, 2018 00:58
SortDescriptors (July 18)
public struct SortDescriptor<Element> {
private let keyPath: PartialKeyPath<Element>
private let comparator: (Any, Any) -> ComparisonResult
// For abitrary `Value` types, the consumer has to provide the entire Comparator
public init<Value>(
_ keyPath: KeyPath<Element, Value>,
using comparator: @escaping (Value, Value) -> ComparisonResult)
{
// Run any SwiftUI view as a Mac app.
import Cocoa
import SwiftUI
NSApplication.shared.run {
VStack {
Text("Hello, World")
.padding()
.background(Capsule().fill(Color.blue))