struct ComparableComparator<Compared> : SortComparator, Sendable where Compared : Comparable

<aside> πŸ’‘ Comparable ν”„λ‘œν† μ½œμ„ μ€€μˆ˜ν•˜λŠ” νƒ€μž…μ— λŒ€ν•œ 비ꡐ μ•Œκ³ λ¦¬μ¦˜. Comparable ν”„λ‘œν† μ½œμ˜ κ΅¬ν˜„μ²΄, 즉 비ꡐ μ—°μ‚°μžλ₯Ό 톡해 μΈμŠ€ν„΄μŠ€λ₯Ό λΉ„κ΅ν•œλ‹€.

</aside>

iOS 16 μ΄μ „κΉŒμ§€λŠ” ComparableComparator에 직접 μ ‘κ·Όν•  일이 μ—†μ—ˆλ‹€. μ• ν”Œ λ¬Έμ„œμ— μ˜ν•˜λ©΄ ComparableComparatorλ₯Ό μ‚¬μš©ν•˜λŠ” 방법은 KeypathComparatorλ₯Ό μƒμ„±ν•˜λ©΄μ„œ comparator 인자λ₯Ό μ „λ‹¬ν•˜μ§€ μ•ŠλŠ” κ²ƒλΏμ΄μ—ˆλŠ”λ°, KeypathComparatorμ—μ„œ comparator 정보λ₯Ό μ‘°νšŒν•  수 μžˆλŠ” 방법을 μ œκ³΅ν•˜μ§€ μ•Šμ•˜κΈ° λ•Œλ¬Έμ΄λ‹€.

2023λ…„(iOS 17+, …)에 μƒμ„±μžκ°€ μΆ”κ°€λ˜λ©΄μ„œ κ°œλ°œμžλ“€μ΄ ν•΄λ‹Ή ꡬ쑰체에 μ ‘κ·Όν•  수 있게 λ˜μ—ˆλ‹€. SortComparator의 μ‚¬μš©μ²˜μ—μ„œ μ‚¬μš©λœλ‹€.

λͺ¨μ•„보기

init(order: SortOrder = .forward)

// conforming SortComparator
func compare(_ lhs: Compared, _ rhs; Compared) -> ComparisonResult
var order: SortOrder

// SortComparator inherits Hashable
func hash(into hasher: inout Hasher)
var hashValue: Int { get }

// Hashable inherits Equatable
static func == (a: ComparableComparator<Compared>, b: ComparableComparator<Compared>) -> Bool
static func != (lhs: ComparableComparator<Compared>, rhs: ComparableComparator<Compared>) -> Bool

참고자료