From 7d88744f0a3db6b78fc2d2e8704adf84ea064d01 Mon Sep 17 00:00:00 2001 From: Ivan Vorobei Date: Tue, 25 Jan 2022 21:02:34 +0300 Subject: [PATCH] Added mac os. --- Package.swift | 5 ++- README.md | 33 +++++++++++++- ...geExtension.swift => ImageExtension.swift} | 45 +++++++++++++++++-- Sources/SFSymbols/SFSymbol.swift | 2 - 4 files changed, 78 insertions(+), 7 deletions(-) rename Sources/SFSymbols/{UIImageExtension.swift => ImageExtension.swift} (75%) diff --git a/Package.swift b/Package.swift index 7cac0b1..fc4bb33 100644 --- a/Package.swift +++ b/Package.swift @@ -6,7 +6,10 @@ let package = Package( name: "SFSymbols", defaultLocalization: "en", platforms: [ - .iOS(.v13), .watchOS(.v6), .tvOS(.v13) + .iOS(.v13), + .watchOS(.v6), + .tvOS(.v13), + .macOS(.v11) ], products: [ .library( diff --git a/README.md b/README.md index 5970692..a9d4783 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,24 @@ If you prefer not to use any of dependency managers, you can integrate manually. ## Usage -To create image: +### SwiftUI + +To create an image: + +```swift +Image(.trash.circle) +``` + +With a font: + +```swift +Image(.plus) + .font(.body) +``` + +### UIKit + +To create an image: ```swift let image = UIImage(.trash.circle) @@ -36,6 +53,20 @@ If need with specific font, use this: let image = UIImage(.plus, font: UIFont.preferredFont(forTextStyle: .body)) ``` +### AppKit + +To create an image: + +```swift +let image = NSImage(.trash.circle) +``` + +If need with specific font, use this: + +```swift +let image = NSImage(.plus, font: UIFont.preferredFont(forTextStyle: .body)) +``` + ## Russian Community Я веду [телеграм-канал](https://sparrowcode.io/telegram), там публикую новости и туториалы.
diff --git a/Sources/SFSymbols/UIImageExtension.swift b/Sources/SFSymbols/ImageExtension.swift similarity index 75% rename from Sources/SFSymbols/UIImageExtension.swift rename to Sources/SFSymbols/ImageExtension.swift index 7510afc..1ec06e9 100644 --- a/Sources/SFSymbols/UIImageExtension.swift +++ b/Sources/SFSymbols/ImageExtension.swift @@ -19,6 +19,44 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. + +#if canImport(SwiftUI) +import SwiftUI + +extension Image { + + /** + SFSymbols: Create `SFSymbols` image by symbol. + + - parameter symbol: Symbol. + */ + public init(_ symbol: SFSymbol) { + self.init(systemName: symbol.name) + } +} +#endif + +#if canImport(AppKit) +import AppKit + +extension NSImage { + + #if targetEnvironment(macCatalyst) + + #else + /** + SFSymbols: Create `SFSymbols` image by symbol. + + - parameter symbol: Symbol. + */ + public convenience init(_ symbol: SFSymbol) { + self.init(systemSymbolName: symbol.name, accessibilityDescription: nil)! + } + #endif +} +#endif + +#if canImport(UIKit) import UIKit extension UIImage { @@ -32,7 +70,7 @@ extension UIImage { public convenience init(_ symbol: SFSymbol) { self.init(systemName: symbol.name)! } - + /** SFSymbols: Create `SFSymbols` image by symbol with specific configuration. @@ -45,9 +83,9 @@ extension UIImage { let configuration = UIImage.SymbolConfiguration(pointSize: pointSize, weight: weight) self.init(systemName: symbol.name, withConfiguration: configuration)! } - + /** - SparrowKit: Create `SFSymbols` image by symbol with specific configuration. + SFSymbols: Create `SFSymbols` image by symbol with specific configuration. - parameter symbol: Symbol. - parameter font: Font of image. @@ -58,3 +96,4 @@ extension UIImage { self.init(systemName: symbol.name, withConfiguration: configuration)! } } +#endif diff --git a/Sources/SFSymbols/SFSymbol.swift b/Sources/SFSymbols/SFSymbol.swift index a1ae1d7..26f84a7 100644 --- a/Sources/SFSymbols/SFSymbol.swift +++ b/Sources/SFSymbols/SFSymbol.swift @@ -19,8 +19,6 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -import UIKit - open class SFSymbol { public let name: String