-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move all aliases to a common file, some formatting
- Loading branch information
1 parent
97d8fda
commit 88a4759
Showing
5 changed files
with
44 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,48 @@ | ||
import SwiftUI | ||
|
||
#if canImport(AppKit) | ||
public typealias NSUIImage = NSImage | ||
#elseif canImport(UIKit) | ||
public typealias NSUIImage = UIImage | ||
#endif | ||
|
||
extension Image { | ||
public init(nsuiImage: NSUIImage) { | ||
#if canImport(AppKit) | ||
public init(nsuiImage: NSUIImage) { | ||
self.init(nsImage: nsuiImage) | ||
} | ||
#elseif canImport(UIKit) | ||
public init(nsuiImage: NSUIImage) { | ||
self.init(uiImage: nsuiImage) | ||
#endif | ||
} | ||
#endif | ||
} | ||
|
||
@available(iOS 16.0, macOS 13.0, tvOS 16.0, watchOS 9.0, *) | ||
extension ImageRenderer { | ||
@MainActor | ||
public var nsuiImage: NSUIImage? { | ||
#if canImport(AppKit) | ||
return nsImage | ||
#elseif canImport(UIKit) | ||
return uiImage | ||
#endif | ||
} | ||
@MainActor | ||
public var nsuiImage: NSUIImage? { | ||
#if canImport(AppKit) | ||
return nsImage | ||
#elseif canImport(UIKit) | ||
return uiImage | ||
#else | ||
return nil | ||
#endif | ||
} | ||
} | ||
|
||
#if canImport(AppKit) | ||
extension NSImage { | ||
public var cgImage: CGImage? { | ||
guard let imageData = self.tiffRepresentation, | ||
let bitmap = NSBitmapImageRep(data: imageData) else { | ||
return nil | ||
} | ||
return bitmap.cgImage | ||
} | ||
|
||
@available(macOS 11.0, *) | ||
public convenience init?(systemName: String) { | ||
self.init(systemSymbolName: systemName, accessibilityDescription: systemName) | ||
} | ||
public var cgImage: CGImage? { | ||
guard | ||
let imageData = self.tiffRepresentation, | ||
let bitmap = NSBitmapImageRep(data: imageData) | ||
else { | ||
return nil | ||
} | ||
|
||
return bitmap.cgImage | ||
} | ||
|
||
@available(macOS 11.0, *) | ||
public convenience init?(systemName: String) { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
mattmassicotte
Author
Owner
|
||
self.init(systemSymbolName: systemName, accessibilityDescription: systemName) | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
That's a great addition....