Skip to content

Commit

Permalink
Prefer checking module availability over the os check (#268)
Browse files Browse the repository at this point in the history
* refactor: prefer checking module availability over the os check for `AssetImageProvider`

* refactor: prefer checking module availability over the os check for `Color+RGBA`
  • Loading branch information
MojtabaHs authored Oct 11, 2023
1 parent e7b49f0 commit 2443543
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions Sources/MarkdownUI/Extensibility/AssetImageProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public struct AssetImageProvider: ImageProvider {
}

private func image(url: URL) -> PlatformImage? {
#if os(macOS)
#if canImport(AppKit)
if let bundle, bundle != .main {
return bundle.image(forResource: self.name(url))
} else {
Expand All @@ -61,15 +61,15 @@ extension ImageProvider where Self == AssetImageProvider {

#if canImport(UIKit)
private typealias PlatformImage = UIImage
#elseif os(macOS)
#elseif canImport(AppKit)
private typealias PlatformImage = NSImage
#endif

extension Image {
fileprivate init(platformImage: PlatformImage) {
#if canImport(UIKit)
self.init(uiImage: platformImage)
#elseif os(macOS)
#elseif canImport(AppKit)
self.init(nsImage: platformImage)
#endif
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/MarkdownUI/Utility/Color+RGBA.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +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 os(macOS)
#if canImport(AppKit)
self.init(
nsColor: .init(name: nil) { appearance in
if appearance.bestMatch(from: [.aqua, .darkAqua]) == .aqua {
Expand Down

0 comments on commit 2443543

Please sign in to comment.