From 9f8d9ce0e014b2cb525cee850cbe0b41fe50c395 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20R=C3=B6nnqvist?= Date: Mon, 2 Dec 2024 17:17:09 +0100 Subject: [PATCH] Improve the ergonomics of the `Availability.Domain` constants --- Sources/SymbolKit/SymbolGraph/Platform.swift | 20 +++++++------ .../Symbol/Availability/Domain.swift | 30 +++++++++---------- 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/Sources/SymbolKit/SymbolGraph/Platform.swift b/Sources/SymbolKit/SymbolGraph/Platform.swift index d261a32..c377c72 100644 --- a/Sources/SymbolKit/SymbolGraph/Platform.swift +++ b/Sources/SymbolKit/SymbolGraph/Platform.swift @@ -46,27 +46,29 @@ extension SymbolGraph { guard let os = operatingSystem?.name else { return nil } - switch os { + + let domain: Symbol.Availability.Domain + switch operatingSystem?.name { case "macosx", "macos": - return SymbolGraph.Symbol.Availability.Domain.macOS + domain = .macOS case "ios": if environment == "macabi" { - return SymbolGraph.Symbol.Availability.Domain.macCatalyst - + domain = .macCatalyst } else { - return SymbolGraph.Symbol.Availability.Domain.iOS + domain = .iOS } case "watchos": - return SymbolGraph.Symbol.Availability.Domain.watchOS + domain = .watchOS case "tvos": - return SymbolGraph.Symbol.Availability.Domain.tvOS + domain = .tvOS case "visionos": - return SymbolGraph.Symbol.Availability.Domain.visionOS + domain = .visionOS case "linux": - return SymbolGraph.Symbol.Availability.Domain.linux + domain = .linux default: return "Unsupported OS: \(os)" } + return domain.rawValue } public init(architecture: String? = nil, vendor: String? = nil, operatingSystem: OperatingSystem? = nil, environment: String? = nil) { diff --git a/Sources/SymbolKit/SymbolGraph/Symbol/Availability/Domain.swift b/Sources/SymbolKit/SymbolGraph/Symbol/Availability/Domain.swift index 879584c..06ae3a2 100644 --- a/Sources/SymbolKit/SymbolGraph/Symbol/Availability/Domain.swift +++ b/Sources/SymbolKit/SymbolGraph/Symbol/Availability/Domain.swift @@ -41,76 +41,76 @@ extension SymbolGraph.Symbol.Availability { in Swift, or availability applies to particular versions of Swift. */ - public static let swift = "Swift" + public static let swift = Domain(rawValue: "Swift") /** The Swift Package Manager Package Description Format. */ - public static let swiftPM = "SwiftPM" + public static let swiftPM = Domain(rawValue: "SwiftPM") /** Apple's macOS operating system. */ - public static let macOS = "macOS" + public static let macOS = Domain(rawValue: "macOS") /** An application extension for the macOS operating system. */ - public static let macOSAppExtension = "macOSAppExtension" + public static let macOSAppExtension = Domain(rawValue: "macOSAppExtension") /** The iOS operating system. */ - public static let iOS = "iOS" + public static let iOS = Domain(rawValue: "iOS") /** An application extension for the iOS operating system. */ - public static let iOSAppExtension = "iOSAppExtension" + public static let iOSAppExtension = Domain(rawValue: "iOSAppExtension") /** The watchOS operating system. */ - public static let watchOS = "watchOS" + public static let watchOS = Domain(rawValue: "watchOS") /** An application extension for the watchOS operating system. */ - public static let watchOSAppExtension = "watchOSAppExtension" + public static let watchOSAppExtension = Domain(rawValue: "watchOSAppExtension") /** The tvOS operating system. */ - public static let tvOS = "tvOS" + public static let tvOS = Domain(rawValue: "tvOS") /** An application extension for the tvOS operating system. */ - public static let tvOSAppExtension = "tvOSAppExtension" + public static let tvOSAppExtension = Domain(rawValue: "tvOSAppExtension") /** The Mac Catalyst platform. */ - public static let macCatalyst = "macCatalyst" + public static let macCatalyst = Domain(rawValue: "macCatalyst") /** An application extension for the Mac Catalyst platform. */ - public static let macCatalystAppExtension = "macCatalystAppExtension" + public static let macCatalystAppExtension = Domain(rawValue: "macCatalystAppExtension") /** The visionOS operating system. */ - public static let visionOS = "visionOS" + public static let visionOS = Domain(rawValue: "visionOS") /** An application extension for the visionOS operating system. */ - public static let visionOSAppExtension = "visionOSAppExtension" + public static let visionOSAppExtension = Domain(rawValue: "visionOSAppExtension") /** A Linux-based operating system, but not a specific distribution. */ - public static let linux = "Linux" + public static let linux = Domain(rawValue: "Linux") } }