From 8f6affc8958f2747053e1a1f50e10bac0cfb5263 Mon Sep 17 00:00:00 2001 From: kirk <103068565+kirkbig@users.noreply.github.com> Date: Sun, 31 Dec 2023 07:31:11 -0700 Subject: [PATCH] fix macCatalyst build failure: re-order `#if canImport(UIKit)` (#283) by placing `#if canImport(UIKit)` first, it means that building for `#if targetEnvironment(macCatalyst)` doesn't fail attempting to use and link in `AppKit` things (since `macCatalyst` apps can link both `UIKit` and `AppKit` --- .../Extensibility/AssetImageProvider.swift | 6 ++--- Sources/MarkdownUI/Utility/Color+RGBA.swift | 22 +++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Sources/MarkdownUI/Extensibility/AssetImageProvider.swift b/Sources/MarkdownUI/Extensibility/AssetImageProvider.swift index 074ec81c..abeb0030 100644 --- a/Sources/MarkdownUI/Extensibility/AssetImageProvider.swift +++ b/Sources/MarkdownUI/Extensibility/AssetImageProvider.swift @@ -38,14 +38,14 @@ public struct AssetImageProvider: ImageProvider { } private func image(url: URL) -> PlatformImage? { - #if canImport(AppKit) + #if canImport(UIKit) + return UIImage(named: self.name(url), in: self.bundle, with: nil) + #elseif canImport(AppKit) if let bundle, bundle != .main { return bundle.image(forResource: self.name(url)) } else { return NSImage(named: self.name(url)) } - #elseif canImport(UIKit) - return UIImage(named: self.name(url), in: self.bundle, with: nil) #endif } } diff --git a/Sources/MarkdownUI/Utility/Color+RGBA.swift b/Sources/MarkdownUI/Utility/Color+RGBA.swift index 58d55a8d..583e9a4c 100644 --- a/Sources/MarkdownUI/Utility/Color+RGBA.swift +++ b/Sources/MarkdownUI/Utility/Color+RGBA.swift @@ -17,17 +17,7 @@ extension Color { /// - light: The light appearance color value. /// - dark: The dark appearance color value. public init(light: @escaping @autoclosure () -> Color, dark: @escaping @autoclosure () -> Color) { - #if canImport(AppKit) - self.init( - nsColor: .init(name: nil) { appearance in - if appearance.bestMatch(from: [.aqua, .darkAqua]) == .aqua { - return NSColor(light()) - } else { - return NSColor(dark()) - } - } - ) - #elseif os(watchOS) + #if os(watchOS) self = dark() #elseif canImport(UIKit) self.init( @@ -42,6 +32,16 @@ extension Color { } } ) + #elseif canImport(AppKit) + self.init( + nsColor: .init(name: nil) { appearance in + if appearance.bestMatch(from: [.aqua, .darkAqua]) == .aqua { + return NSColor(light()) + } else { + return NSColor(dark()) + } + } + ) #endif } }