File tree Expand file tree Collapse file tree
Sources/SwiftUIKit/Images Expand file tree Collapse file tree Original file line number Diff line number Diff line change 88
99import Foundation
1010
11- #if canImport(AppKit)
11+ #if canImport(UIKit)
12+ import UIKit
13+
14+ public extension UIImage {
15+
16+ /// Create a resized copy of the image.
17+ func resized( to size: CGSize ) -> UIImage ? {
18+ UIGraphicsBeginImageContextWithOptions ( size, false , scale)
19+ draw ( in: CGRect ( origin: CGPoint . zero, size: size) )
20+ let result = UIGraphicsGetImageFromCurrentImageContext ( )
21+ UIGraphicsEndImageContext ( )
22+ return result
23+ }
24+ }
25+ #elseif canImport(AppKit)
1226import AppKit
1327
1428public extension NSImage {
@@ -26,23 +40,6 @@ public extension NSImage {
2640}
2741#endif
2842
29-
30- #if canImport(UIKit)
31- import UIKit
32-
33- public extension UIImage {
34-
35- /// Create a resized copy of the image.
36- func resized( to size: CGSize ) -> UIImage ? {
37- UIGraphicsBeginImageContextWithOptions ( size, false , scale)
38- draw ( in: CGRect ( origin: CGPoint . zero, size: size) )
39- let result = UIGraphicsGetImageFromCurrentImageContext ( )
40- UIGraphicsEndImageContext ( )
41- return result
42- }
43- }
44- #endif
45-
4643public extension ImageRepresentable {
4744
4845 /// Create a resized copy of the image with a new height.
Original file line number Diff line number Diff line change 88
99import SwiftUI
1010
11- #if canImport(AppKit )
12- import class AppKit . NSImage
11+ #if canImport(UIKit )
12+ import class UIKit . UIImage
1313
1414/**
1515 This typealias helps bridging UIKit and AppKit when working
1616 with images in a multi-platform context.
1717 */
18- public typealias ImageRepresentable = NSImage
19- #endif
20-
21- #if canImport(UIKit)
22- import class UIKit. UIImage
18+ public typealias ImageRepresentable = UIImage
19+ #elseif canImport(AppKit)
20+ import class AppKit. NSImage
2321
2422/**
2523 This typealias helps bridging UIKit and AppKit when working
2624 with images in a multi-platform context.
2725 */
28- public typealias ImageRepresentable = UIImage
26+ public typealias ImageRepresentable = NSImage
2927#endif
3028
3129public extension Image {
You can’t perform that action at this time.
0 commit comments