10
10
11
11
import Foundation
12
12
13
- #if canImport(UIKit)
14
- import UIKit
15
- #elseif canImport(AppKit)
16
- import AppKit
17
- #endif
18
-
19
13
/// A color in the sRGB color space, with normalized components.
20
14
public struct SRGBColor : Codable , Equatable {
21
15
/// The normalized red component of the color.
@@ -39,34 +33,4 @@ public struct SRGBColor: Codable, Equatable {
39
33
self . blue = blue
40
34
self . alpha = alpha
41
35
}
42
-
43
- #if canImport(UIKit)
44
-
45
- /// Creates a new instance from the given `UIColor`.
46
- public init ? ( from uiColor: UIColor ) {
47
- guard let components = uiColor. cgColor. components, components. count >= 4 else { return nil }
48
-
49
- self . red = UInt8 ( Double ( components [ 0 ] ) * 255.0 )
50
- self . green = UInt8 ( Double ( components [ 1 ] ) * 255.0 )
51
- self . blue = UInt8 ( Double ( components [ 2 ] ) * 255.0 )
52
- self . alpha = Double ( components [ 3 ] )
53
- }
54
-
55
- #elseif canImport(AppKit)
56
-
57
- /// Creates a new instance from the given `NSColor`.
58
- public init ? ( from nsColor: NSColor ) {
59
- // The normalization factor this initializer uses to convert between NSColor and sRGB
60
- // color spaces as described by
61
- // <https://developer.apple.com/library/content/qa/qa1576/_index.html>.
62
- let normalizationFactor = 255.99999
63
-
64
- guard let color = nsColor. usingColorSpace ( . sRGB) else { return nil }
65
-
66
- self . red = UInt8 ( Double ( color. redComponent) * normalizationFactor)
67
- self . green = UInt8 ( Double ( color. greenComponent) * normalizationFactor)
68
- self . blue = UInt8 ( Double ( color. blueComponent) * normalizationFactor)
69
- self . alpha = Double ( color. alphaComponent)
70
- }
71
- #endif
72
36
}
0 commit comments