Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 26 additions & 14 deletions Examples/Reminders/Helpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,18 @@ import SharingGRDB
import SwiftUI

extension Color {
public struct HexRepresentation: QueryBindable, QueryRepresentable {
public struct HexRepresentation: QueryRepresentable {
public var queryOutput: Color
public var queryBinding: QueryBinding {
guard let hexValue else {
struct InvalidColor: Error {}
return .invalid(InvalidColor())
}
return .int(hexValue)
}
public init(queryOutput: Color) {
self.queryOutput = queryOutput
}
public init(decoder: inout some QueryDecoder) throws {
let hex = try Int(decoder: &decoder)
public init(hexValue: Int64) {
self.init(
queryOutput: Color(
red: Double((hex >> 24) & 0xFF) / 0xFF,
green: Double((hex >> 16) & 0xFF) / 0xFF,
blue: Double((hex >> 8) & 0xFF) / 0xFF,
opacity: Double(hex & 0xFF) / 0xFF
red: Double((hexValue >> 24) & 0xFF) / 0xFF,
green: Double((hexValue >> 16) & 0xFF) / 0xFF,
blue: Double((hexValue >> 8) & 0xFF) / 0xFF,
opacity: Double(hexValue & 0xFF) / 0xFF
)
)
}
Expand All @@ -36,3 +28,23 @@ extension Color {
}
}
}

extension Color.HexRepresentation: QueryBindable {
public init?(queryBinding: StructuredQueriesCore.QueryBinding) {
guard case .int(let hexValue) = queryBinding else { return nil }
self.init(hexValue: hexValue)
}
public var queryBinding: QueryBinding {
guard let hexValue else {
struct InvalidColor: Error {}
return .invalid(InvalidColor())
}
return .int(hexValue)
}
}

extension Color.HexRepresentation: QueryDecodable {
public init(decoder: inout some QueryDecoder) throws {
try self.init(hexValue: Int64(decoder: &decoder))
}
}
18 changes: 9 additions & 9 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ let package = Package(
.package(url: "https://github.com/pointfreeco/xctest-dynamic-overlay", from: "1.5.0"),
.package(url: "https://github.com/pointfreeco/swift-sharing", from: "2.3.0"),
.package(url: "https://github.com/pointfreeco/swift-snapshot-testing", from: "1.18.4"),
.package(url: "https://github.com/pointfreeco/swift-structured-queries", from: "0.15.0"),
.package(url: "https://github.com/pointfreeco/swift-structured-queries", from: "0.16.0"),
],
targets: [
.target(
Expand Down