Skip to content

Commit d84ca0d

Browse files
authored
StructuredQueries 0.16 support (#150)
Just a minor change to the Reminders demo, which defined a custom query representation.
1 parent ec6eed5 commit d84ca0d

File tree

4 files changed

+38
-26
lines changed

4 files changed

+38
-26
lines changed

Examples/Examples.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Examples/Reminders/Helpers.swift

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,18 @@ import SharingGRDB
22
import SwiftUI
33

44
extension Color {
5-
public struct HexRepresentation: QueryBindable, QueryRepresentable {
5+
public struct HexRepresentation: QueryRepresentable {
66
public var queryOutput: Color
7-
public var queryBinding: QueryBinding {
8-
guard let hexValue else {
9-
struct InvalidColor: Error {}
10-
return .invalid(InvalidColor())
11-
}
12-
return .int(hexValue)
13-
}
147
public init(queryOutput: Color) {
158
self.queryOutput = queryOutput
169
}
17-
public init(decoder: inout some QueryDecoder) throws {
18-
let hex = try Int(decoder: &decoder)
10+
public init(hexValue: Int64) {
1911
self.init(
2012
queryOutput: Color(
21-
red: Double((hex >> 24) & 0xFF) / 0xFF,
22-
green: Double((hex >> 16) & 0xFF) / 0xFF,
23-
blue: Double((hex >> 8) & 0xFF) / 0xFF,
24-
opacity: Double(hex & 0xFF) / 0xFF
13+
red: Double((hexValue >> 24) & 0xFF) / 0xFF,
14+
green: Double((hexValue >> 16) & 0xFF) / 0xFF,
15+
blue: Double((hexValue >> 8) & 0xFF) / 0xFF,
16+
opacity: Double(hexValue & 0xFF) / 0xFF
2517
)
2618
)
2719
}
@@ -36,3 +28,23 @@ extension Color {
3628
}
3729
}
3830
}
31+
32+
extension Color.HexRepresentation: QueryBindable {
33+
public init?(queryBinding: StructuredQueriesCore.QueryBinding) {
34+
guard case .int(let hexValue) = queryBinding else { return nil }
35+
self.init(hexValue: hexValue)
36+
}
37+
public var queryBinding: QueryBinding {
38+
guard let hexValue else {
39+
struct InvalidColor: Error {}
40+
return .invalid(InvalidColor())
41+
}
42+
return .int(hexValue)
43+
}
44+
}
45+
46+
extension Color.HexRepresentation: QueryDecodable {
47+
public init(decoder: inout some QueryDecoder) throws {
48+
try self.init(hexValue: Int64(decoder: &decoder))
49+
}
50+
}

Package.resolved

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ let package = Package(
3939
.package(url: "https://github.com/pointfreeco/xctest-dynamic-overlay", from: "1.5.0"),
4040
.package(url: "https://github.com/pointfreeco/swift-sharing", from: "2.3.0"),
4141
.package(url: "https://github.com/pointfreeco/swift-snapshot-testing", from: "1.18.4"),
42-
.package(url: "https://github.com/pointfreeco/swift-structured-queries", from: "0.15.0"),
42+
.package(url: "https://github.com/pointfreeco/swift-structured-queries", from: "0.16.0"),
4343
],
4444
targets: [
4545
.target(

0 commit comments

Comments
 (0)