From be2a655c405fea4ffc4786b5bdb17f19f17f89e2 Mon Sep 17 00:00:00 2001 From: Sven Weidauer Date: Sat, 2 Jan 2021 21:17:41 +0100 Subject: [PATCH] Match formatting used by Xcode. Turns out Xcode requires two digits for hex colors values. Single digits get repeated. --- .../Generators/AssetCatalogGenerator.swift | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/Sources/LibMakeColors/Generators/AssetCatalogGenerator.swift b/Sources/LibMakeColors/Generators/AssetCatalogGenerator.swift index 964c6f5..9cc8698 100644 --- a/Sources/LibMakeColors/Generators/AssetCatalogGenerator.swift +++ b/Sources/LibMakeColors/Generators/AssetCatalogGenerator.swift @@ -67,10 +67,10 @@ private extension Color { "color" : { "color-space" : "srgb", "components" : { - "alpha" : "0x\(String(alpha, radix: 16))", - "blue" : "0x\(String(blue, radix: 16))", - "green" : "0x\(String(green, radix: 16))", - "red" : "0x\(String(red, radix: 16))" + "alpha" : "\(Double(alpha) / 0xFF)", + "blue" : "0x\(blue, radix: 16, width: 2)", + "green" : "0x\(green, radix: 16, width: 2)", + "red" : "0x\(red, radix: 16, width: 2)" } }, "idiom" : "universal" @@ -88,6 +88,22 @@ private extension Color { } } +extension String.StringInterpolation { + mutating func appendInterpolation( + _ value: I, + radix: Int, + width: Int = 0, + uppercase: Bool = true + ) { + var string = String(value, radix: radix, uppercase: uppercase) + if width > string.count { + string.insert(contentsOf: String(repeating: "0", count: width - string.count), at: string.startIndex) + } + + appendLiteral(string) + } +} + private let group = """ { "properties" : {