Skip to content

Commit cd3c47b

Browse files
authored
Merge pull request #17 from andreyoshev/master
Hard support for old iOS versions
2 parents 900db38 + 3720d50 commit cd3c47b

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

Sources/XcodeExport/XcodeColorExporter.swift

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,16 @@ final public class XcodeColorExporter {
8787
if let darkComponents = colorPair.dark?.toRgbComponents() {
8888
contents.append("""
8989
static var \(colorPair.light.name): UIColor {
90-
UIColor { traitCollection -> UIColor in
91-
if traitCollection.userInterfaceStyle == .dark {
92-
return UIColor(red: \(darkComponents.red), green: \(darkComponents.green), blue: \(darkComponents.blue), alpha: \(darkComponents.alpha))
93-
} else {
94-
return UIColor(red: \(lightComponents.red), green: \(lightComponents.green), blue: \(lightComponents.blue), alpha: \(lightComponents.alpha))
90+
if #available(iOS 13.0, *) {
91+
UIColor { traitCollection -> UIColor in
92+
if traitCollection.userInterfaceStyle == .dark {
93+
return UIColor(red: \(darkComponents.red), green: \(darkComponents.green), blue: \(darkComponents.blue), alpha: \(darkComponents.alpha))
94+
} else {
95+
return UIColor(red: \(lightComponents.red), green: \(lightComponents.green), blue: \(lightComponents.blue), alpha: \(lightComponents.alpha))
96+
}
9597
}
98+
} else {
99+
return UIColor(red: \(lightComponents.red), green: \(lightComponents.green), blue: \(lightComponents.blue), alpha: \(lightComponents.alpha))
96100
}
97101
}\n
98102
""")

Tests/XcodeExportTests/XcodeColorExporterTests.swift

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,16 @@ final class XcodeColorExporterTests: XCTestCase {
4444
4545
extension UIColor {
4646
static var colorPair1: UIColor {
47-
UIColor { traitCollection -> UIColor in
48-
if traitCollection.userInterfaceStyle == .dark {
49-
return UIColor(red: 0.000, green: 0.000, blue: 0.000, alpha: 1.000)
50-
} else {
51-
return UIColor(red: 1.000, green: 1.000, blue: 1.000, alpha: 1.000)
47+
if #available(iOS 13.0, *) {
48+
UIColor { traitCollection -> UIColor in
49+
if traitCollection.userInterfaceStyle == .dark {
50+
return UIColor(red: 0.000, green: 0.000, blue: 0.000, alpha: 1.000)
51+
} else {
52+
return UIColor(red: 1.000, green: 1.000, blue: 1.000, alpha: 1.000)
53+
}
5254
}
55+
} else {
56+
return UIColor(red: 1.000, green: 1.000, blue: 1.000, alpha: 1.000)
5357
}
5458
}
5559
static var colorPair2: UIColor {

0 commit comments

Comments
 (0)