@@ -2,26 +2,18 @@ import SharingGRDB
2
2
import SwiftUI
3
3
4
4
extension Color {
5
- public struct HexRepresentation : QueryBindable , QueryRepresentable {
5
+ public struct HexRepresentation : QueryRepresentable {
6
6
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
- }
14
7
public init ( queryOutput: Color ) {
15
8
self . queryOutput = queryOutput
16
9
}
17
- public init ( decoder: inout some QueryDecoder ) throws {
18
- let hex = try Int ( decoder: & decoder)
10
+ public init ( hexValue: Int64 ) {
19
11
self . init (
20
12
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
25
17
)
26
18
)
27
19
}
@@ -36,3 +28,23 @@ extension Color {
36
28
}
37
29
}
38
30
}
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
+ }
0 commit comments