From 13cb5d69b227fd606cd80f88b0c95a79200b4e8b Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Sat, 1 Feb 2025 17:33:56 -0800 Subject: [PATCH] Add conversion to UIUserInterfaceStyle. --- .../Defaults/UserInterfaceColorPalette.swift | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/Shared/Defaults/UserInterfaceColorPalette.swift b/Shared/Defaults/UserInterfaceColorPalette.swift index a01abec09..48b0f8dbe 100644 --- a/Shared/Defaults/UserInterfaceColorPalette.swift +++ b/Shared/Defaults/UserInterfaceColorPalette.swift @@ -6,9 +6,13 @@ // Copyright © 2025 Ranchero Software. All rights reserved. // +#if os(iOS) + import Foundation +import UIKit enum UserInterfaceColorPalette: Int, CustomStringConvertible, CaseIterable { + case automatic = 0 case light = 1 case dark = 2 @@ -16,11 +20,24 @@ enum UserInterfaceColorPalette: Int, CustomStringConvertible, CaseIterable { var description: String { switch self { case .automatic: - return NSLocalizedString("Automatic", comment: "Automatic") + NSLocalizedString("Automatic", comment: "Automatic") case .light: - return NSLocalizedString("Light", comment: "Light") + NSLocalizedString("Light", comment: "Light") case .dark: - return NSLocalizedString("Dark", comment: "Dark") + NSLocalizedString("Dark", comment: "Dark") + } + } + + var uiUserInterfaceStyle: UIUserInterfaceStyle { + switch self { + case .automatic: + .unspecified + case .light: + .light + case .dark: + .dark } } } + +#endif