|
33 | 33 | /// An extension to the `Color` type that adds an initializer to create a |
34 | 34 | /// `Color` instance from a hexadecimal string. |
35 | 35 | extension Color { |
36 | | - // swiftlint:disable function_body_length |
37 | | - |
38 | 36 | /// Initializes a `Color` instance from a hexadecimal string. |
39 | 37 | /// |
40 | 38 | /// - Parameter hex: A hexadecimal string representation of the color, in the |
|
49 | 47 | let blue: UInt64 |
50 | 48 |
|
51 | 49 | switch hex.count { |
52 | | - case 3: // RGB (12-bit) |
53 | | - (alpha, red, green, blue) = ( |
54 | | - 255, (int >> 8) * 17, (int >> 4 & 0xF) * 17, (int & 0xF) * 17 |
55 | | - ) |
56 | | - case 6: // RGB (24-bit) |
57 | | - (alpha, red, green, blue) = |
58 | | - (255, int >> 16, int >> 8 & 0xFF, int & 0xFF) |
59 | | - case 8: // ARGB (32-bit) |
60 | | - (alpha, red, green, blue) = |
61 | | - (int >> 24, int >> 16 & 0xFF, int >> 8 & 0xFF, int & 0xFF) |
| 50 | + case 3: // RGB (12-bit) |
| 51 | + (alpha, red, green, blue) = ( |
| 52 | + 255, (int >> 8) * 17, (int >> 4 & 0xF) * 17, (int & 0xF) * 17 |
| 53 | + ) |
| 54 | + case 6: // RGB (24-bit) |
| 55 | + (alpha, red, green, blue) = |
| 56 | + (255, int >> 16, int >> 8 & 0xFF, int & 0xFF) |
| 57 | + case 8: // ARGB (32-bit) |
| 58 | + (alpha, red, green, blue) = |
| 59 | + (int >> 24, int >> 16 & 0xFF, int >> 8 & 0xFF, int & 0xFF) |
62 | 60 |
|
63 | | - default: |
64 | | - (alpha, red, green, blue) = (255, 0, 0, 0) |
| 61 | + default: |
| 62 | + (alpha, red, green, blue) = (255, 0, 0, 0) |
65 | 63 | } |
66 | 64 |
|
67 | 65 | self.init( |
|
72 | 70 | opacity: Double(alpha) / 255 |
73 | 71 | ) |
74 | 72 | } |
75 | | - // swiftlint:enable function_body_length |
76 | 73 | } |
77 | 74 | #endif |
0 commit comments