Skip to content

Commit

Permalink
maybe fixing icon?
Browse files Browse the repository at this point in the history
  • Loading branch information
henrik-dmg committed Dec 15, 2020
1 parent 7a81c06 commit c0877f6
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions Sources/HPOpenWeather/DataTypes/WeatherIcon.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import UIKit
#elseif canImport(AppKit)
import AppKit
#endif
import SwiftUI
import Foundation

public enum WeatherIcon: String, Codable, CaseIterable {
Expand All @@ -29,39 +28,31 @@ public enum WeatherIcon: String, Codable, CaseIterable {

}

@available(OSX 11.0, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
extension WeatherIcon {
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
public extension WeatherIcon {

#if canImport(UIKit)

public func filledUIImage(withConfiguration configuration: UIImage.Configuration? = nil) -> UIImage? {
func filledUIImage(withConfiguration configuration: UIImage.Configuration? = nil) -> UIImage? {
UIImage(systemName: makeIconName(filled: true), withConfiguration: configuration)
}

public func outlineUIImage(withConfiguration configuration: UIImage.Configuration? = nil) -> UIImage? {
func outlineUIImage(withConfiguration configuration: UIImage.Configuration? = nil) -> UIImage? {
UIImage(systemName: makeIconName(filled: false), withConfiguration: configuration)
}

#elseif canImport(AppKit)

public func filledNSImage(accessibilityDescription: String? = nil) -> NSImage? {
func filledNSImage(accessibilityDescription: String? = nil) -> NSImage? {
NSImage(systemSymbolName: makeIconName(filled: true), accessibilityDescription: accessibilityDescription)
}

public func outlineNSImage(accessibilityDescription: String? = nil) -> NSImage? {
func outlineNSImage(accessibilityDescription: String? = nil) -> NSImage? {
NSImage(systemSymbolName: makeIconName(filled: false), accessibilityDescription: accessibilityDescription)
}

#endif

public func filledImage() -> Image {
Image(systemName: makeIconName(filled: true))
}

public func outlineImage() -> Image {
Image(systemName: makeIconName(filled: false))
}

private func makeIconName(filled: Bool) -> String {
let iconName: String
switch self {
Expand Down Expand Up @@ -95,3 +86,22 @@ extension WeatherIcon {
}

}

#if canImport(SwiftUI)

import SwiftUI

@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
public extension WeatherIcon {

func filledImage() -> SwiftUI.Image {
SwiftUI.Image(systemName: makeIconName(filled: true))
}

func outlineImage() -> SwiftUI.Image {
SwiftUI.Image(systemName: makeIconName(filled: false))
}

}

#endif

0 comments on commit c0877f6

Please sign in to comment.