Skip to content

Commit a9a696a

Browse files
committed
#14 Add support for Foundation.SortDescriptor
1 parent 72051f9 commit a9a696a

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Sources/CoreModel/SortDescriptor.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
// Copyright © 2015 PureSwift. All rights reserved.
77
//
88

9+
import Foundation
10+
911
public extension FetchRequest {
1012

1113
struct SortDescriptor: Codable, Equatable, Hashable, Sendable {
@@ -20,3 +22,18 @@ public extension FetchRequest {
2022
}
2123
}
2224
}
25+
26+
// MARK: - Foundation
27+
28+
#if canImport(Darwin)
29+
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
30+
public extension FetchRequest.SortDescriptor {
31+
32+
/// Creates a ``FetchRequest.SortDescriptor`` from a ``Foundation.SortDescriptor``
33+
init<Root: NSObject>(_ sortDescriptor: Foundation.SortDescriptor<Root>) {
34+
let sortDescriptor = NSSortDescriptor(sortDescriptor)
35+
self.property = PropertyKey(rawValue: sortDescriptor.key ?? "")
36+
self.ascending = sortDescriptor.ascending
37+
}
38+
}
39+
#endif

0 commit comments

Comments
 (0)